I think the solution to your problem is to create an executable jar. Something that can be run as follows:
java -jar myapp.jar
"look ma, no classpath" :-)
The secret is to add the "Main-Class" and "Class-Path" entries to the jar manifest file. This tells java what to run and which banks should be loaded into the classpath:
<jar destfile="${jar.file}" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${jar.main.class}" /> <attribute name="Class-Path" value="${jar.classpath}" /> </manifest> </jar>
To help create the classpath, ANT has a really useful manifestclasspath task:
<manifestclasspath property="jar.classpath" jarfile="${jar.file}"> <classpath> <fileset dir="${dist.dir}/lib" includes="*.jar"/> </classpath> </manifestclasspath>
Thus, using this example, at runtime, java expects the parameters to be in the lib subdirectory (the task will generate relative links).
Eclipse integration is complex. The best approach for managing a class of classes is to use a dependency manager like ivy , which has an Eclipse plugin. Thus, both ANT and Eclipse use the same mechanism to manage build dependencies.
Finally, for a complete working example, take a look at:
- Class not found with Ant, Ivy and JUnit - error in build.xml file?
Hope this helps.
Mark o'connor
source share