I have created a executable jar file using build.
<target name="deploy" depends="compile">
<jar jarfile="${deploy.home}/${app.name}.jar" basedir="${build.home}">
<manifest>
<attribute name="Main-Class" value="abc.xyz"/>
</manifest>
</jar>
Here the xyz call has the main method to execute the whole program..
public static void main(String[] args) {
File buildFile = new File("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
}
The jar file is being created successfuly. When I execute the like java -jar appname.jar
, it is throwing exception --
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Project
at abc.xyz.main(xyz.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Project
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
The project class not found. Its there in ant.jar
.
But when i execute the abc.java
class simply by on command prompt java abc its working fine.
Pleased help me to get the cause? and its solution.