开发者

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 tes开发者_Python百科t.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?


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)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜