0

現在、外部依存関係を使用する jar があります。すべての外部依存関係を内部にパッケージ化する jar を作成しようとしていますが、1 つの jar だけが提供されます。この質問が何度も出ているのを見ましたが、まだわかりません。私は Ant を使用しており、ここで見た例のいくつかをコピーしました。外部(現在は内部)のjarファイルを参照するためにzipgroupfilesetを使用しています。zipgroupfileset を追加するとすぐに、ランナー クラスが見つからないというランタイム エラーが発生しました。

    <?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="ExcelDemo">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../../Program Files (x86)/eclipse"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <property name="external-lib-dir" value="lib\poi-3.9" />
    <property name="external-lib-dir2" value="lib\poi-3.9\lib" />
    <property name="external-lib-dir3" value="lib\poi-3.9\ooxml-lib" />
    <path id="ExcelDemo.classpath">
        <pathelement location="bin"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src" excludes="**/*.launch, **/*.java"/>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </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="bin" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="ExcelDemo.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects">
        <ant antfile="${ExcelSensitize.location}/build.xml" inheritAll="false" target="clean"/>
        <ant antfile="${ExcelSensitize.location}/build.xml" inheritAll="false" target="build">
            <propertyset>
                <propertyref name="build.compiler"/>
            </propertyset>
        </ant>
    </target>
    <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="RunnerClass">
        <java classname="runner.RunnerClass" failonerror="true" fork="yes">
            <classpath refid="ExcelDemo.classpath"/>
        </java>
    </target>
    <target name="jar" description="Create a jar for this project">
        <manifestclasspath property="lib.list" jarfile="Test.jar">
            <classpath refid="ExcelDemo.classpath" /> 
        </manifestclasspath>
        <jar jarfile="Test.jar" includes="*.class" basedir="bin">
            <zipgroupfileset dir="${external-lib-dir}" includes="*.jar"/>
            <zipgroupfileset dir="${external-lib-dir2}" includes="*.jar"/>
            <zipgroupfileset dir="${external-lib-dir3}" includes="*.jar"/>
            <manifest>
                <attribute name="Class-Path" value="${lib.list}" /> 
                <attribute name="Main-Class" value="runner.RunnerClass" /> 
            </manifest>
        </jar>
    </target>
</project>
4

2 に答える 2

1

物事を簡単にするために:

  • コンパイル用に別のソース jarを作成します。次に、ソースを含まない別のコンパイル済み jar を用意します。
  • サードパーティの jar は含めないでください。代わりに、Ant で Ivy を使用してください。Ant は、必要な jar を自動的にダウンロードします。実際、 だけを含むソースを見たことがあるivy.jarので、ソースを unjar すると Ivy が自動的に設定されます。と入力するantと、すべてがビルドされます。

別の方法として、現在パッケージ化されているプロジェクトの数であるMavenを見ることができます。実際、jar がオープン ソース プロジェクトの場合は、おそらく OSS Maven リポジトリでホストできます。このように、コンパイル済みの jar を手動でダウンロードする必要さえありません。必要に応じて、Maven プロジェクトを構成して、それを実行します。

于 2013-07-15T20:57:03.200 に答える
0

問題は、jar タスクで basedir="bin" を使用していることだと思います。次に、zipgroupfileset のパスを bin/${external-lib-dir} に変換します

于 2013-07-15T20:20:20.997 に答える