Coping with the Boot Class Path
Some projects, such as MethodHandles, require us to develop Java code and test cases under packages like java.dyn
. Classes in packages under java
cannot be loaded by the normal means of setting CLASSPATH
or using the -cp
flag. The JVM will throw an exception like this:
No Format | ||
---|---|---|
| ||
$ java -cp "$mypath" java.dyn.MethodHandleBytecodeTest Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.dyn |
Instead, you must put your classes on the boot class path, as follows:
No Format | ||
---|---|---|
| ||
$ java -Xbootclasspath/a:"$mypath" java.dyn.MethodHandleBytecodeTest invoke toString invoke mh=java.dyn.hotspot.VMH@15ff48b ... |
If you are running JUnit, you will also need to place the JAR for JUnit on the boot class path. You can fish the JAR out of your NetBeans distribution (e.g., under NetBeans 6.1.app/Contents/Resources/NetBeans/java2/modules/ext
), or you can download it from SourceForge.
NetBeans Modifications
In order to run test correctly from inside NetBeans, you have to hack the boot class path. Add the following line to nbproject/project.properties
:
No Format | ||
---|---|---|
| ||
run.jvmargs=-Xbootclasspath/a:"${build.classes.dir}:${libs.junit.classpath}" |
The quotes are important, since there might be spaces in the path names.
(I would like put the setting in build.xml
, so that it will have the required effect outside of NetBeans. No success with this yet.)