我正在尝试使用ant构建应用程序。我建立的时候一切似乎都很好,但我不断得到上述错误,因为我到目前为止已经尝试过了。
java -jar dist/pmml_export.jar
java -cp ".:log4j-1.2.16.jar" -jar dist/pmml_export.jar
java -cp log4j-1.2.16.jar -jar dist/pmml_export.jar
我加倍检查,看看布局是否在我正在引用的jar中,它就在那里。我对ant和log4j都很新,所以我可能犯了一个明显的错误,但我只是没有看到它。这是我的build.xml
。
<?xml version="1.0"?>
<project name="pmml_export" default="archive">
<target name="init">
<mkdir dir="build/classes" />
<mkdir dir="dist" />
</target>
<path id="compile.classpath">
<fileset dir="build/classes" includes="*.class" />
</path>
<property name="ant.dir" value="apache-log4j-1.2.16"/>
<path id="classpath">
<fileset dir="${ant.dir}" includes="**/*.jar"/>
</path>
<target name="exceptions" depends="init">
<javac srcdir="src/exceptions" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Exceptions compiled! </echo>
</target>
<target name="symbol-table" depends="exceptions" >
<javac srcdir="src/translator/symbol_table" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Symbol table compiled! </echo>
</target>
<target name="parser" depends="symbol-table" >
<javac srcdir="src/translator/parser" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Parser compiled! </echo>
</target>
<target name="lexer" depends="parser" >
<javac srcdir="src/translator/lexer" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Lexer compiled! </echo>
</target>
<target name="translator" depends="lexer" >
<javac srcdir="src/translator" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Translator compiled! </echo>
</target>
<target name="exporter" depends="translator" >
<javac srcdir="src/pmml_export" destdir="build/classes" classpathref="compile.classpath" />
<echo> Exporter compiled! </echo>
</target>
<target name="archive" depends="exporter" >
<property name="manifest.mf" location="dist/manifest.txt" />
<manifest file="${manifest.mf}" >
<attribute name="Main-Class" value="pmml_export.PMML_Export"/>
</manifest>
<jar destfile="dist/pmml_export.jar" manifest="${manifest.mf}"
basedir="build/classes" />
</target>
<target name="run" depends="archive">
<java jar="dist/pmml_exporter.jar" fork="true">
<classpath>
<path refid="classpath"/>
<path location="dist/pmml_exporter.jar"/>
</classpath>
</java>
</target>
</project>
答案 0 :(得分:1)
使用-jar
选项时,会忽略-cp
和-classpath
选项。使用-jar
选项嵌入类路径的正确方法是在jar的MANIFEST.MF
文件中设置Class-Path指令。