Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有JavaEE(EJB)、ANT和Jenkins/Hudson的Eclipse_Eclipse_Jakarta Ee_Ant_Jenkins_Ejb 3.0 - Fatal编程技术网

带有JavaEE(EJB)、ANT和Jenkins/Hudson的Eclipse

带有JavaEE(EJB)、ANT和Jenkins/Hudson的Eclipse,eclipse,jakarta-ee,ant,jenkins,ejb-3.0,Eclipse,Jakarta Ee,Ant,Jenkins,Ejb 3.0,我的目标是在Jenkins上构建一个企业Java应用程序。该应用程序由4个项目组成(客户端接口、webapplication(包括Faces)、EJB应用程序(包括JPA)、EAR容器项目) 当Eclipse将此项目部署到glassfish服务器时,它将Webapplication(war文件)、客户端接口(jar文件)和EJB接口(jar文件)组装到一个ear文件中 现在,如果我想使用持续集成,我需要在CI服务器jenkins上实现同样的功能 我的第一个想法是用ant解决这个问题,所以我使用E

我的目标是在Jenkins上构建一个企业Java应用程序。该应用程序由4个项目组成(客户端接口、webapplication(包括Faces)、EJB应用程序(包括JPA)、EAR容器项目)

当Eclipse将此项目部署到glassfish服务器时,它将Webapplication(war文件)、客户端接口(jar文件)和EJB接口(jar文件)组装到一个ear文件中

现在,如果我想使用持续集成,我需要在CI服务器jenkins上实现同样的功能

我的第一个想法是用ant解决这个问题,所以我使用Eclipse的导出功能并为项目生成构建文件

问题是生成的构建文件引用了项目目录之外的JavaEE库(如Glassfish运行时、JPA库等)。大约有30个图书馆

这意味着我不能在jenkins上使用该文件,因为缺少该库。当然我可以复制这些,但我不认为应该这样做

那么,在CI服务器上构建JavaEE企业应用程序的最佳方法是什么?我必须自己编写ANT脚本并将库复制到项目中吗?还是我遗漏了一些明显的东西?

使用Maven。
Maven允许在单个xml文件(pom)中定义所有依赖项,这些依赖项将在编译阶段从internet自动下载。
Maven附带了一组插件,以促进持续集成,比如能够启动容器、运行测试并自动关闭它。 Maven与jenkins的本土融合。
Maven定义了一个复杂的生命周期,该生命周期专为此类问题而设计,允许使用jenkins触发的单个命令编译、运行单元测试、打包、运行集成测试和部署


Maven无疑是这里的解决方案。

因为我没有找到适合我的东西,所以我自己编写了一个ant脚本来满足我的需求

如果这对将来的任何人都有帮助,以下是我的解决方案: `



`

您还可以使用项目上下文菜单中的“Export…>General\Ant Buildfile”在Eclipse中自动创建build.xml。这样,正确的类路径将生成到项目中已经可用的JAR中


如果项目之间存在依赖关系,则您只需配置一个要在Jenkins上运行的构建文件,因为它会自动调用其他项目中的构建文件。

请注意,如果4个相互依赖的不同项目,您必须将它们打包到引用所有子项目的公共父项目中。(多模块maven项目)。您可能需要安装和配置一个nexus服务器,以允许将您自己的工件(项目打包的所有jar、war、ear)公开给maven依赖机制(maven公共存储库上仅公开公共框架工件)虽然我得出的结论是maven将是更好的解决方案,但由于我们大学的开发环境,我不能切换到maven。这是一个非常好的ant文件,可以轻松地与jenkins集成,但是如何运行测试呢?您可以尝试使用嵌入式应用程序服务器,或者尝试将测试作为外部应用程序运行。
<project basedir="." default="build" name="Project">

<available property="glassfishdir" value="/opt/glassfish3/glassfish/modules" 
         file="/opt/glassfish3/glassfish/modules" type="dir" />

<!-- ########### Property Declarations ###################################################################################################################  -->
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="builddir" value="build" />
<property name="outputartifacts" value="out" />

<property name="web.name" value="ProjectWeb" />
<property name="web.projectpath" value="ProjectWeb"/>
<property name="web.src" value="${web.projectpath}/src" />
<property name="web.builddir" value="${builddir}/web" />
<property name="web.builddir.classes" value="${web.builddir}/WEB-INF/classes"/>

<property name="ejb.name" value="ProjectEJB" />
<property name="ejb.projectpath" value="ProjectEJB"/>
<property name="ejb.src" value="${ejb.projectpath}/src"/>
<property name="ejb.builddir" value="${builddir}/ejb" />
<property name="ejb.builddir.classes" value="${ejb.builddir}/classes" />

<property name="ejbclient.name" value="ProjectEJBClient" />
<property name="ejbclient.projectpath" value="ProjectEJBClient"/>
<property name="ejbclient.src" value="${ejbclient.projectpath}/src"/>
<property name="ejbclient.builddir" value="${builddir}/ejbclient" />
<property name="ejbclient.builddir.classes" value="${ejbclient.builddir}/classes"/>

<property name="ear.name" value="ProjectApplication" />
<property name="ear.dir" value="ProjectEAR" />

<!-- ########### Main Targets ###################################################################################################################   -->
<target name="build" depends="create-ear">
</target>

<target name="clean-build">
    <antcall target="clean" />
    <antcall target="build" />
</target>

<target name="clean">
    <delete dir="${builddir}"/>
    <delete dir="${outputartifacts}"/>
</target>

<target name="init">
    <mkdir dir="${outputartifacts}" />
</target>

<!-- ########### EJB App ###################################################################################################################    -->
<target name="init-ejb" depends="init">
    <mkdir dir="${ejb.builddir}" /> 
    <copy includeemptydirs="false" todir="${ejb.builddir.classes}">
        <fileset dir="${ejb.src}">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>
<target name="build-ejb" depends="init-ejb">
    <javac debug="true" debuglevel="${debuglevel}" destdir="${ejb.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
        <src path="${ejb.src}"/>
        <classpath>
            <fileset dir="${glassfishdir}">
                <include name="**/*.jar"/>
            </fileset>  

            <fileset dir="${outputartifacts}">
                <include name="**/*.jar"/>
            </fileset>                  
        </classpath>
    </javac>
</target>

<!-- ########### WEB ###################################################################################################################    -->
<target name="init-web" depends="init">
    <mkdir dir="${web.builddir.classes}"/>  
    <copy includeemptydirs="false" todir="${web.builddir}">
        <fileset dir="${web.projectpath}/WebContent">
        </fileset>
    </copy>
    <copy includeemptydirs="false" todir="${web.builddir.classes}">
        <fileset dir="${web.src}">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>

<target depends="init-web,create-ejb-client" name="build-web">
    <javac debug="true" debuglevel="${debuglevel}" destdir="${web.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
        <src path="${web.src}"/>
        <classpath>
            <fileset dir="${glassfishdir}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="out/">
                <include name="**/*.jar"/>
            </fileset>  
        </classpath>
    </javac>
</target>
<!-- ############## EJB CLIENT ################################################################################################################ -->
<target name="init-ejb-client" depends="init">
    <mkdir dir="${ejbclient.builddir}"/>
    <copy includeemptydirs="false" todir="${ejbclient.builddir.classes}">
        <fileset dir="${ejbclient.src}">
            <exclude name="**/*.java"/>
        </fileset>  
    </copy>
</target>


<target depends="init-ejb-client" name="build-ejb-client">
    <javac debug="true" debuglevel="${debuglevel}" destdir="${ejbclient.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
        <src path="${ejbclient.src}"/>
        <classpath>
            <fileset dir="${glassfishdir}">
                <include name="**/*.jar"/>
            </fileset>          
        </classpath>
    </javac>
</target>


<!-- ############ CREATE ARCHIVES################################################################################################################## -->
<target name="create-web" depends="build-web">
    <war destfile="${outputartifacts}/${web.name}.war" basedir="${web.builddir}" webxml="${web.projectpath}/WebContent/WEB-INF/web.xml"/>
</target>

<target name="create-ejb-client" depends="build-ejb-client">
    <jar destfile="${outputartifacts}/${ejbclient.name}.jar" basedir="${ejbclient.builddir.classes}" includes="**/*"/>
</target>

<target name="create-ejb" depends="build-ejb">
    <jar destfile="${outputartifacts}/${ejb.name}.jar" basedir="${ejb.builddir.classes}" includes="**/*">
        <manifest>
            <attribute name="Class-Path" value="${ejbclient.name}.jar"/>
        </manifest>
    </jar>
</target>

<target name="create-ear" depends="create-ejb-client,create-web,create-ejb">
    <ear destfile="${outputartifacts}/${ear.name}.ear" appxml="${ear.dir}/EarContent/META-INF/application.xml">
        <fileset dir="${outputartifacts}" includes="*.jar,*.war"/>
    </ear>
</target>


</project>