0

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 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>
3
  • 3
    The -cp argument is ignored when using the -jar argument. You need to tell Ant to specify the classpath as Class-Path entry of JAR's /META-INF/MANIFEST.MF file. Commented Jun 1, 2011 at 18:28
  • What OS? On Windows -cp a.jar;b.jar Commented Jun 1, 2011 at 18:33
  • @Op De Cirkel: The OS is Ubuntu 10.04 and I'm running it on a VM Player. The host OS is Windows Vista. Commented Jun 1, 2011 at 18:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That fixed it. I added this line here to the manifest spec: <attribute name="Class-Path" value="apache-log4j-1.2.16/log4j-1.2.16.jar" /> Thanks Edwin
@Erik, glad to hear about the success. You're welcome, anytime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.