Coding District
Coding District

Reputation: 11931

Eclipse Ant Builder problem

I made a custom ant script to automatically create a jar file each time I do a build.

This is how it looks like:

<?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 > then I specified the location of the above xml file.

However, when I run it by doing:

java -jar TestProj.jar

I get a NoClassDefFoundError test/testproj/TestProj

I'm using Eclipse in Ubuntu. TestProj is the name of the class and it's in package test.testproj

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

Upvotes: 2

Views: 1763

Answers (1)

VonC
VonC

Reputation: 1328312

Did you try with:

<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>

just to see if it solves the issue?

The Ant Task mentions:

This task forms an implicit FileSet and supports most attributes of <fileset> (dir becomes basedir)

That means you are trying to jar any class within the root bin/test/testproj (so TestProj get included), instead of referencing all classes within root bin (which would include test.testproj.TestProj)

Upvotes: 2

Related Questions