BootClassPath

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:

what can happen when you develop in java.dyn
$ 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:

successfully running your java.dyn code
$ 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:

NetBeans properties hacking boot class path
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.)

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

© 2010, Oracle Corporation and/or its affiliates
Powered by Atlassian Confluence
Oracle Social Media Participation Policy Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact