Eclipse Ant Problem with Builder

I created a custom ant script to automatically generate a jar file every time I do a build.

This is how it looks:

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

<project name="TestProj" basedir="." default="jar">
  <property name="dist" value="dist" />
  <property name="build" value="bin/test/testproj" />
  <target name="jar">
      <jar destfile="${dist}/TestProj.jar">
          <manifest>
              <attribute name="Main-Class" value="test.testproj.TestProj" />
          </manifest>
          <fileset dir="${build}" />
      </jar>
  </target>
</project> 

      

I added it by right clicking my project> properties> builders> clicked new> ant builder> after which I specified the location of the above XML file.

However, when I run it by doing:

java -jar TestProj.jar

      

I am getting NoClassDefFoundError test / testproj / TestProj

I am using Eclipse on Ubuntu. TestProj is the name of the class and in the package test.testproj

I'm sure there is something wrong with the manifest and probably the location of the xml file, but I'm not sure how to fix this. Any ideas?

+2


a source to share


1 answer


Have you tried:

<property name="build" value="bin" /> <!-- instead of bin/test/testproj -->
  <target name="jar">
      <jar destfile="${dist}/TestProj.jar">
          <manifest>
              <attribute name="Main-Class" value="test.testproj.TestProj" />
          </manifest>
          <fileset dir="${build}" />
      </jar>
  </target>

      

to see if it solves the problem?



Ant Task mentions:

This task forms an implicit FileSet and supports most of the attributes <fileset>

( dir

becomes the base
)

This means you are trying to compile any class in the root directory bin/test/testproj

(which is why TestProj

get is included) instead of referencing all classes inside root bin

(which will include test.testproj.TestProj

)

+2


a source







All Articles