You can, however, specify the classpath. Â yippee.
I'm having trouble doing this though.
java -jar ignores all -cp and environment variable settings, so the only way to give a classpath is through the jar's manifest.
So with this in mind, why does the following simple example work as expected with the compile and test targets, but the jar file generated complain of not finding com.sun.jdi.BootStrap when i try to run it with java -jar?
the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import com.sun.jdi.*; import com.sun.jdi.connect.*;
import java.util.*;
public class ObjectGraph {
public static void main( String[] args ) {
System.out.println( "Classpath set to :" ); System.out.println( System.getProperty( "java.class.path" ) );
Bootstrap bs = new Bootstrap(); VirtualMachineManager vmm = bs.virtualMachineManager();
List connectors = vmm.allConnectors();
ListIterator iter = connectors.listIterator();
while( iter.hasNext() ) { System.out.println( ( ( Connector ) iter.next() ).description() ); } } } |
the ant build.xml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <project name="ObjectGraph" default="compile" basedir=".">
<description> Builds ObjectGraph to varying degrees </description> <!-- set global properties for this build --> <property name="build" location="build"/> <property name="JDIlib" location="/usr/java/j2sdk1.4.2/lib/tools.jar"/>
<target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> </target>
<target name="compile" depends="init" description="compile the source" > <!-- Compile the java code from ${src} into ${build}--> <record name="compilelog.txt" action="start" append="false" emacsmode="true"/>
<javac srcdir="." destdir="${build}" debug="true" classpath="${JDIlib}" debuglevel="source,lines,vars" />
<record name="compilelog.txt" action="stop"/> </target>
<target name="jar" depends="compile" description="generate the distribution" >
<!-- Put everything in ${build} into the ObjectGraph.jar file--> <jar jarfile="ObjectGraph.jar" basedir="${build}" index="true"> <manifest> <attribute name="Class-Path" value="${JDIlib}"/> <attribute name="Main-Class" value="ObjectGraph"/> </manifest> </jar> </target>
<target name="test" depends="compile" description="start up the application for testing" > <record name="runlog.txt" action="start" append="false" emacsmode="true"/>
<java classname="ObjectGraph" fork="true" > <classpath> <pathelement location="${build}"/> <pathelement location="${JDIlib}"/> </classpath> </java>
<record name="runlog.txt" action="stop"/> </target>
<target name="clean" description="clean up" > <!-- Delete the ${build} directory tree --> <delete dir="${build}"/> <delete file="compilelog.txt"/> <delete file="runlog.txt"/> </target>
</project> |
You may have to alter the value of JDIlib in the ant file to get it running on your system.
No doubt there's some trivial, obvious reason for this annoying behaviour, and i would
love for someone to enlighten me.
Cheers