渐变生成Eclipse项目EAR项目

时间:2023-01-17 12:47:53

I'm migrating a legacy project from ant to gradle (to use its dependency management and build features) and I'm facing a problem when generating the eclipse projects. The big problem today is because the project has some subprojects that are split into war and jar packages to deploy into a single ear. This is made by ant today. To use gradle I split the eclipse projects into separate jar and war projects. So I have the following structure:

我将遗留项目从ant迁移到gradle(使用它的依赖管理和构建特性),并且在生成eclipse项目时遇到了一个问题。今天的大问题是,项目中有一些子项目被分割为war和jar包,以部署到单个ear中。这是今天蚂蚁做的。要使用gradle,我将eclipse项目分为独立的jar和war项目。所以我有以下结构:

ProjectRoot
-lib
-Project1.jar
-Project1.war
-Project2.jar
-Project3.war

And here's my gradle file:

这是我的评分文件:

apply plugin: 'ear'
def jboss_home = '/home/augusto/Development/servers/jboss6X' 
def deploy_name = 'default'

allprojects {
    repositories {
        mavenCentral()
    }
    apply plugin: 'eclipse'
    apply plugin: 'eclipse-wtp'
}

dependencies {
    deploy project(path: 'Project1.jar', configuration: 'archives')
    deploy project(path: 'Project1.war', configuration: 'archives')
    deploy project(path: 'Project2.jar', configuration: 'archives')
    deploy project(path: 'Project2.war', configuration: 'archives')
    earlib fileTree(dir: 'lib', include: '*.jar')
}

ear {
    libDirName = "lib"
    deploymentDescriptor {
        applicationName = "MyApp"
        initializeInOrder = true
        displayName = "MyApp"
        module("Project1.jar", "java")
        module("Project2.jar", "java")
        webModule("Project1.war", "/Project1")
        webModule("Project2.war", "/Project2")
    }
}

project('MyJarLib') {
    apply plugin: 'java'
    dependencies {
        compile files('../lib/ajar.jar')
        compile fileTree(dir: jboss_home + '/common/lib', include: '*.jar')
        compile fileTree(dir: jboss_home + '/client', include: '*.jar')
        compile fileTree(dir: jboss_home + '/lib', include: '*.jar')
        compile fileTree(dir: jboss_home + '/server/' + deploy_name + '/lib', include: '*.jar')
    }
}

project('Project1.jar') {
    apply plugin: 'java'
    dependencies {
        compile 'org.apache.poi:poi:3.2-FINAL', 'jdom:jdom:1.1'
        compile project(':MyJarLib.jar')
    }
}

project('Project1.war') {
    apply plugin: 'war'
}

project('Project2.jar') {
    apply plugin: 'java'
    dependencies {
        compile 'net.sf.jasperreports:jasperreports:3.7.0', 'jdom:jdom:1.1'
        compile project(':MyJarLib.jar')
    }
}

project('Project2.war') {
    apply plugin: 'war'
}

I've put the ear plugin in the sub projects to deploy it to server using eclipse. If I let just jar, I cannot deploy it to server using eclipse (and I want to do this to use the hot deploy feature from jboss 6). Our team has big productivity problem to maitain this application because of ant builds. It takes almost 15 minutes to test a feature because they can't use hot deploy... The problem with eclipse: it does not generate a single ear in its deploy. It deploys the packages separately and the server fails to deploy. The problem with the gradle build: it is generating the right structure, but it is creating application.xml files inside each jar project (because of the ear plugin). I use only the root application.xml. Can you help me solve both this problems? Thanks.

我将ear插件放在子项目中,以便使用eclipse将其部署到服务器。如果我只让jar,我不能使用eclipse将它部署到服务器(我想这样做是为了使用jboss 6的热部署特性)。测试一个特性需要15分钟,因为他们不能使用热部署……eclipse的问题是:在其部署中没有生成一个ear。它单独部署包,服务器无法部署。渐变构建的问题是:它正在生成正确的结构,但它正在创建应用程序。每个jar项目中的xml文件(因为ear插件)。我只使用根应用程序。你能帮我解决这两个问题吗?谢谢。

EDIT

I've managed to make eclipse deploy my project right using the tips in the comments. In all java projects I've put this configuration:

我已经使用评论中的技巧成功地让eclipse部署了我的项目。在所有java项目中,我都设置了以下配置:

apply plugin: 'ear'
ear.onlyIf { false }
ear {
    //appDirName 'src/main/java'
    libDirName '../lib'
}

sourceSets {
    main {
    java {
        srcDir 'src/main/application'
    }
    }
}
eclipse.wtp.facet {
    facet name: 'jst.ejb', version: '3.1'
    facet name: 'java', version: '1.6'
}
eclipse.classpath.file{
    withXml {
    def nodes = it.asNode().children().findAll{it.@kind == 'lib'}
    nodes.each {
        if(it.attributes[0] == null)
            it.appendNode('attributes').appendNode('attribute', [name:'org.eclipse.jst.component.dependency', value: '../lib'])
        else
            it.attributes[0].attribute[0].@value = '../lib'
    }
    }
}

I've put the ear plugin, so gradle generates the project ready to deploy in eclipse. The ear.onlyIf { false } makes gradle not generate the artifact in ear structure. After this I've changed the eclipse preferences to set the facet of the project to EJB and changed the classpath entries to deploy the dependencies in the ear lib directory instead of the root of the ear. My problem now is in the build from gradle. When I call gradle ear it is generating lots of dependency errors due the fact that the web container library is not in the classpath... So I have a lot of classnotfound exceptions. If I put all the classes as dependencies from my project, it will mess with the eclipse classpath (and deploy). The question is: Is there a way to provide a provided dependency for java projects in gradle and is there an easy way to provide all those jars from jboss instead of each one?

我已经放置了ear插件,这样gradle就可以生成在eclipse中部署的项目。耳朵。只有当{false}使gradle不能在ear结构中生成工件时。在此之后,我更改了eclipse首选项,将项目的facet设置为EJB,并更改了类路径条目,以在ear lib目录中部署依赖项,而不是ear的根。我现在的问题是来自等级的构建。当我调用gradle ear时,它产生了大量的依赖错误,因为web容器库不在类路径中……我有很多classnotfound的例外。如果我将所有类作为项目的依赖项放置,将会破坏eclipse类路径(和部署)。问题是:是否有一种方法可以在gradle中为java项目提供依赖性,是否有一种简单的方法可以从jboss而不是每个jboss提供所有jar ?

1 个解决方案

#1


0  

I've managed to make all work. Using the workarounds in my edit part of the question and some points of this article. Here's what I have to do:

我已设法使一切顺利进行。使用我的问题编辑部分中的工作区和本文的一些要点。我必须做的是:

configurations {
    provided
}

sourceSets {
    main {
    compileClasspath += configurations.provided
    compileClasspath += configurations.compile
    compileClasspath += configurations.runtime
    java {
        srcDir 'src/main/application'
    }
    }
}

This made possible to use provided in the dependencies of all my projects and it does not mess with the eclipse project.

这使得在我所有项目的依赖项中使用提供的功能成为可能,并且不会影响到eclipse项目。

#1


0  

I've managed to make all work. Using the workarounds in my edit part of the question and some points of this article. Here's what I have to do:

我已设法使一切顺利进行。使用我的问题编辑部分中的工作区和本文的一些要点。我必须做的是:

configurations {
    provided
}

sourceSets {
    main {
    compileClasspath += configurations.provided
    compileClasspath += configurations.compile
    compileClasspath += configurations.runtime
    java {
        srcDir 'src/main/application'
    }
    }
}

This made possible to use provided in the dependencies of all my projects and it does not mess with the eclipse project.

这使得在我所有项目的依赖项中使用提供的功能成为可能,并且不会影响到eclipse项目。