Importing Ear project generated by gradle in eclipse

1.9k Views Asked by At

I am using gradle to set up multi-project build. I have following folder layout for projects:

---RootProject
---- build.gradle
---- settings.gradle
------ JarProject (Utility) 
--------- build.gradle
------ JpaProject (Dependency on JarProject)
--------- build.gradle
------ EjbProject (Dependency on JarProject, JpaProject)
--------- build.gradle
------ WebProject (Dependency on EjbProject)
--------- build.gradle

Tools & Technologies

  • Gradle: 1.6
  • Java: 1.7
  • Eclipse: Juno
  • Server: Glassfish 3.1.2.2

I am able to define multi-project build for the above folder layout. Gradle is able to generate eclipse meta-data for each of the project that I am able to import all projects in to eclipse. Gradle is able to correctly generate ".ear" artifact. However, I am unable to deploy Ear project from eclipse. During deployment eclipse gives NullPointerException.

In order to tell Gradle to generate appropriate facet for EarProject, EjbProject and JpaProject, I have added following code: * EarProject/build.gradle

apply plugin: 'ear'
apply plugin: 'eclipse-wtp'
eclipse {
    wtp {
       facet {
        facet name:'jst.ear', version:'6.0'
       }
    }
}

* EjbProject/build.gradle

apply plugin: 'war'
apply plugin: 'eclipse-wtp'
eclipse {
    wtp {
       facet {
        facet name:'jst.ejb', version:'3.1'
       }
    }
}
  • JpaProject/build.gradle

    apply plugin: 'war' apply plugin: 'eclipse-wtp' eclipse { wtp { facet { facet name:'java', version:'1.6' facet name:'jpt.jpa', version:'2.0' } } }

  • WebProject/build.gradle

    apply plugin: 'war' apply plugin: 'eclipse-wtp' eclipse { wtp { facet { facet name:'java', version:'1.6' facet name:'jst.web', version:'3.0' facet name:'wst.jsdt.web', version:'1.0' } } }

Notice that even though EjbProject and JpaProject are not Web projects, plugin 'war' is applied. Because of this gradle thinks that EjbProject and JpaProject are web projects and creates eclipse meta data accordingly.

  • For EjbProject/JpaProject, the file "org.eclipse.wst.common.component" has following content

    <property name="context-root" value="prj-context"/>

    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>

    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>

Due to this, when I export the EjbProject/JpaProject to ejb-jar or jar file, the eclipse does not create correct jar file.

Another issue is that I am unable to export EarProject to ".ear" file using eclipse "File->Export->Ear File". I get an exception

When I try to deploy EarProject from within eclipse, it gives NullPointerException.

My idea is to deploy EarProject from within eclipse to Glassfish server defined in eclipse and debug the application.

Please give me guidance.

TiA Chir

0

There are 0 best solutions below