开发者

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout

I'm trying to build an application using ant. Everything appears to be fine when I build but I continually get the above error for what I've tried so far.

  • 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

I doubled checked to see if Layout was in the jar I'm referencing and it is there. I'm 开发者_JAVA百科fairly new to both ant and log4j so I could be making an obvious mistake but I'm just not seeing it. Here is my 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>


When you use the -jar option, the -cp and -classpath options are ignored. The proper way to embed the classpath with the -jar option is to set a Class-Path directive in the jar's MANIFEST.MF file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜