Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 204729 - ClassNotFoundException when running JUnit Test with "Compile on Save" on
ClassNotFoundException when running JUnit Test with "Compile on Save" on
Product: javaee
Classification: Unclassified
Component: Web Project
PC Windows Vista
: P2 (vote)
: 7.1
Assigned To: David Konecny
Depends on:
Blocks: 201937
  Show dependency treegraph
Reported: 2011-11-07 07:02 UTC by bht
Modified: 2011-11-29 15:58 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT

testcase in zip file (35.47 KB, application/octet-stream)
2011-11-07 07:02 UTC, bht
Verbose output COS off (51.91 KB, text/plain)
2011-11-08 08:42 UTC, bht
Verbose output COS on (22.28 KB, text/plain)
2011-11-08 08:44 UTC, bht

Note You need to log in before you can comment on or make changes to this bug.
Description bht 2011-11-07 07:02:14 UTC
Created attachment 112889 [details]
testcase in zip file

This is a follow-up from issue 201937 - in fact this new error needs to be fixed also so that 201937 can be verified fixed.

How to use the attached testcase:

- Start NetBeans with a new userdir without importing settings
- Create library JavaDB with files in the GlassFish distribution  <GlassFish install dir>/javadb/lib/
  - derby.jar
  - derbyclient.jar
  - derbynet.jar
- Start JavaDB Server
- Create database testDB if required
- Under Drivers, JavaDB (Network) connect using URL: jdbc:derby://localhost:1527/testDB
- Open project Web
- Verify that "Compile on Save" is off
- Replace the VM run option "javaagent" with your version
  e.g. -javaagent:"C:\Program Files\NetBeans 7.0.1\java\modules\ext\eclipselink\eclipselink-2.2.0.jar"
- Clean and build the project
- Compile the test class MyServiceTest
- Run the test class MyServiceTest

Te test should succeed and it succeeds - this is just test setup.

To reproduce the error:
- Turn "Compile on Save" on
- Run the test class MyServiceTest

The test fails with the following error:

java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceUnitInfo

WARNING: multiple versions of ant detected in path for junit 
     and jar:file:/C:/Program%20Files/glassfish-3.1.1/glassfish/modules/ant.jar!/org/apache/tools/ant/Project.class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(
	at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(
Caused by: java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.initializeFromAgent(
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.premain(
	... 6 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceUnitInfo
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
FATAL ERROR in native method: processing of -javaagent failed

	at java.lang.ClassLoader.loadClass(
	... 10 more
Exception in thread "main" 
Testsuite: ejb.service.MyServiceTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

Testcase: ejb.service.MyServiceTest:null:	Caused an ERROR
Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
Comment 1 Sergey Petrov 2011-11-07 18:04:19 UTC
With these details I see now it may be something similar to initial issue instead of new one, thanks. It may be an issue with incomplete ee api added froms server classpath also( and this api hide proper jpa api) and may be can be fixed by changes in classpath order in project properties. It's just some assumptions without deep evaluation so far.
Comment 2 Sergey Petrov 2011-11-07 18:05:10 UTC
Yet, with my assumtions it still strange as it mean classpath is still different for cos on/off.
Comment 3 David Konecny 2011-11-08 00:37:36 UTC
I cannot reproduce this. I followed your steps exactly and the test passes in both of the cases. Sergey, can you reproduce it? Could anybody who is able to reproduce it turn Ant into verbose mode (in Output window click on Ant Settings icon and set Verbosity Level to "Verbose") and now run test with CoS enabled and save output from Ant and repeat the same with CoS disabled and again save output from Ant and attach both outputs to this issue. That way we can compare how javac is executed and why it fails in one case. Thx.
Comment 4 bht 2011-11-08 08:42:57 UTC
Created attachment 112985 [details]
Verbose output COS off

Product Version: NetBeans IDE Dev (Build 201111040600)
Comment 5 bht 2011-11-08 08:44:13 UTC
Created attachment 112986 [details]
Verbose output COS on

Product Version: NetBeans IDE Dev (Build 201111040600)
Comment 6 Sergey Petrov 2011-11-08 10:48:47 UTC
Just a note It may not be so good to use -javaagent:"C:\Program Files\NetBeans
7.0.1\java\modules\ext\eclipselink\eclipselink-2.2.0.jar" i.e. from 7.0.1 and verify in latest build which already use later eclipselink.
Comment 7 Sergey Petrov 2011-11-08 11:01:29 UTC
>Sergey, can you reproduce it?
no I can't, even tried eclipselin 2.2.0 and 2.3.0 and gf 3.0.1 and 3.1.1 to have different libraries set. hope verbose will help.
Comment 8 David Konecny 2011-11-09 02:36:38 UTC
When COS is enabled parameters for bootclasspath are screwed. Instead of:

'-Xbootclasspath/p:C:\Program Files\NetBeans Dev 201111040600\enterprise\modules\ext\javaee6-endorsed\javax.annotation.jar;C:\Program Files\NetBeans Dev 201111040600\enterprise\modules\ext\javaee6-endorsed\jaxb-api-osgi.jar;C:\Program Files\NetBeans Dev 201111040600\enterprise\modules\ext\javaee6-endorsed\webservices-api-osgi.jar'

there is:


I'm not sure why it should cause NoClassDefFoundError though because C:\Program Files\glassfish-3.1.1\glassfish\modules\javax.persistence.jar is still on regular classpath. So perhaps the cause is somewhere else. I will fix the path first and then we will see.
Comment 9 David Konecny 2011-11-09 21:35:21 UTC
Fixed in web-main #b34154fc468b

The way to reproduce this problem is to start NetBeans IDE from a directory which has a space character in its path (without that issue never happens). When a test from attached test case is run what happens is that unit test must be run with endorsed classpath and jars of this endorsed classpath are in NetBeans installation and will therefore contain a space character in the path. I'm fixing it by quoting path. And I'm also converting path to have platform specific path delimiter.
Comment 10 Quality Engineering 2011-11-10 15:56:38 UTC
Integrated into 'main-golden'
User: David Konecny <>
Log: #204729 - ClassNotFoundException when running JUnit Test with "Compile on Save" on

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo