1

Eclipse と Tomcat 7 サーバーを使用して最初の war ファイルを作成するために、ant ビルドファイルを作成しています。初めてwarファイルを作成するので、少しお手柔らかにお願いします。war ファイルを作成するためのビルド ファイルを取得しましたが、war ファイルを解凍すると、含まれる必要のあるすべてが含まれていないことがわかりました。その結果、アプリケーションを war ファイルの形式で tomcat にデプロイしようとすると、Web コンテナーはアプリケーション内のサーブレットを見つけることができません。入力、出力、およびコードを以下に投稿しています。war ファイルの出力が Eclipse からの入力と一致するように、以下のコードを修正する方法を教えてください。

eclipse プロジェクトの構造は次の

とおりです。 解凍された war ファイルの内容は次のとおりです。

Ant ビルドファイルのコードは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>

<project basedir="C:\mypath\workspace\myapp" name="myapp" default="default">
    <target name="default" depends="setup,compile,buildwar,deploy"></target>

    <target name="setup">
        <mkdir dir="dist" />
        <echo>Copying web into dist</echo>
        <copydir dest="dist/web" src="web" />
        <copydir dest="dist/web/WEB-INF/lib" src="${basedir}/web/WEB-INF/lib" />
    </target>

    <target name="compile">
        <delete dir="${dist.dir}/web/WEB-INF/classes" />
        <mkdir dir="${dist.dir}/web/WEB-INF/classes" />
        <javac destdir="${dist.dir}/web/WEB-INF/classes" srcdir="src">
            <classpath>
                <fileset dir="${basedir}/web/WEB-INF/lib">
                    <include name="*" />
                </fileset>
            </classpath>
        </javac>
        <copy todir="${dist.dir}/web/WEB-INF/classes">
            <fileset dir="src">
                <include name="**/*.properties" />
                <include name="**/*.xml" />
            </fileset>
        </copy>
    </target>

    <target name="buildwar">
        <war basedir="${basedir}/dist/web" destfile="myapp.war"
             webxml="${basedir}/dist/web/WEB-INF/web.xml">
            <exclude name="WEB-INF/**" />
            <webinf dir="${basedir}/dist/web/WEB-INF/">
                <include name="**/*.jar" />
            </webinf>
        </war>
    </target>

    <target name="deploy">
        <copy file="myapp.war" todir="${tomcat.deploydir}" />
    </target>

</project>  

このスクリプトを実行すると、war ファイルのコピーが 3 つ作成されることに注意してください。1冊だけ欲しい。


編集:

Shaunak の提案を試してみたところ、war ファイルを解凍すると、次のような出力

が得られました。Web コンテナーがサーブレットを見つけられないため、結果の war を tomcat にデプロイしても 404 エラーが発生します。出力に web.xml または myapp.xml が見つからないようで、jar ファイルの依存関係が war ファイルにも存在しないようですが、良いニュースは、パッケージ フォルダーに Java ファイルとクラスの両方が含まれているように見えることです。ファイル。


2番目の編集:

これは、Eclipse が生成した ant ビルド ファイルです。次のビルド ファイルを実行すると作成されるはずの .war ファイルはどこにありますか? そして、warファイルの名前は何ですか?

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
          Any modifications will be overwritten.
          To include a user specific buildfile here, simply create one in the same
          directory with the processing instruction <?eclipse.ant.import?>
          as the first entry and export the buildfile again. --><project basedir="." default="build" name="myapp">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../../java/eclipse"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>
    <path id="Web App Libraries.libraryclasspath"/>
    <path id="EAR Libraries.libraryclasspath"/>
    <path id="myapp.classpath">
        <pathelement location="web/WEB-INF/classes"/>
        <pathelement location="web/WEB-INF/lib/ant.jar"/>
        <pathelement location="web/WEB-INF/lib/jaxen.jar"/>
        <pathelement location="web/WEB-INF/lib/xalan.jar"/>
        <pathelement location="web/WEB-INF/lib/xerces.jar"/>
        <pathelement location="lib/commons-logging-1.1.3.jar"/>
        <pathelement location="lib/commons-logging-1.1.3-javadoc.jar"/>
        <pathelement location="lib/commons-logging-1.1.3-sources.jar"/>
        <pathelement location="lib/commons-logging-1.1.3-test-sources.jar"/>
        <pathelement location="lib/commons-logging-adapters-1.1.3.jar"/>
        <pathelement location="lib/commons-logging-api-1.1.3.jar"/>
        <pathelement location="lib/commons-logging-tests.jar"/>
        <pathelement location="web/WEB-INF/lib/jstl-1.2.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-1.1.3.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-1.1.3-javadoc.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-1.1.3-sources.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-1.1.3-test-sources.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-adapters-1.1.3.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-api-1.1.3.jar"/>
        <pathelement location="web/WEB-INF/lib/commons-logging-tests.jar"/>
        <pathelement location="web/WEB-INF/lib/servlet-api.jar"/>
        <pathelement location="web/WEB-INF/lib/jsp-api.jar"/>
        <path refid="Web App Libraries.libraryclasspath"/>
        <path refid="EAR Libraries.libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="web/WEB-INF/classes"/>
        <copy includeemptydirs="false" todir="web/WEB-INF/classes">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="web/WEB-INF/classes"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="web/WEB-INF/classes" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="myapp.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
    <target name="GetBI">
        <java classname="myapp.plotters.GetBI" failonerror="true" fork="yes">
            <classpath refid="myapp.classpath"/>
        </java>
    </target>
    <target name="GetPlotGIF (2)">
        <java classname="myapp.plotters.GetPlotGIF" failonerror="true" fork="yes">
            <classpath refid="myapp.classpath"/>
        </java>
    </target>
</project>  
4

0 に答える 0