3

私の目標は、エンタープライズJavaアプリケーションをJenkins上に構築することです。アプリケーションは、4つのプロジェクト(クライアント-インターフェース、Webアプリケーション(Facesを含む)、EJBアプリケーション(JPAを含む)、EAR-Container-Project)で構成されています。

EclipseがこのプロジェクトをGlassfishサーバーにデプロイすると、Webアプリケーション(war-file)、Client-Interfaces(jar-file)、およびEJB-Interfaces(jar-file)が1つのear-Fileにアセンブルされます。

ここで、継続的インテグレーションを使用する場合は、CI-Serverjenkinsで同じことを実現する必要があります。

私の最初のアイデアはantでこれを解決することだったので、EclipseのExport-Functionを使用して、プロジェクトのビルドファイルを生成しました。

問題は、生成されたビルドファイルがプロジェクトディレクトリの外部にあるJava EEライブラリ(Glassfish-Runtime、JPA-Libraryなど)を参照していることです。約30の図書館があります。

これは、このライブラリがないため、jenkinsでファイルを使用できないことを意味します。もちろん、これらをコピーすることはできますが、これがどのように行われるべきかとは思いません。

では、Java EEエンタープライズアプリケーションをCIサーバー上に構築するための最良の方法は何ですか?ANT-Scriptをすべて自分で作成し、ライブラリをプロジェクトにコピーする必要がありますか?それとも私は何か明らかなものが欠けていますか?

4

3 に答える 3

4

自分に合ったものが見つからなかったので、自分のニーズに合ったアリのスクリプトを自分で書きました。

これが将来誰かを助けるなら私の解決策はここにあります: `

<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>

`

于 2013-04-19T17:07:56.653 に答える
0

Mavenを使用します。
Mavenでは、すべての依存関係を単一のxmlファイル(pom)で定義できます。依存関係は、コンパイル段階でインターネットから自動的にダウンロードされます。
Mavenには、コンテナーを開始し、テストを実行して自動的に閉じることができるなど、継続的インテグレーションを容易にするプラグインのセットが付属しています。Mavenはjenkinsとネイティブに統合されます。
Mavenは、この種の問題に対応するように設計された複雑なライフサイクルを定義し、jenkinsからトリガーされる単一のコマンドでコンパイル、単体テスト、パッケージ化、統合テストの実行、およびデプロイを可能にします。

Mavenは間違いなくここでの解決策です。

于 2013-03-06T14:29:36.097 に答える
0

プロジェクトのコンテキストメニューから[エクスポート...]>[General\ Ant Buildfile]を使用して、Eclipseでbuild.xmlを自動作成することもできます。このようにして、プロジェクトですでに使用可能なJARに対して正しいクラスパスが生成されます。

プロジェクト間に依存関係がある場合は、Jenkinsで実行するビルドファイルを1つだけ構成する必要があります。これは、他のプロジェクトからビルドファイルを自動的に呼び出すためです。

于 2013-12-27T09:05:42.937 に答える