This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I have a maven project that has a Hibernate config file in src/main/resources. At compile time, Maven copies the hibernate.cfg.xml file into target/classes. When I run a test with maven from a terminal with mvn test -Dtest=BlahBlahTest everything is fine. When I try to run the same test from Netbeans, I get a org.hibernate.DuplicateMappingException. This happens because when running from Netbeans the classpath also includes src/main/resources. I think that this is a bug, since the classpath used when running in Netbeans is different from the one used when running Maven from the command line.
Try disabling "Compile on Save" in the project's properties. For faster test execution, by default you can run test classes directly, bypassing Maven, but this relies on src/main/resources being in the classpath first so that edits to resources are picked up without needing to be copied to target/classes. Can look into whether there is some way that CoS test execution can avoid duplicate entries on the classpath, though I am guessing there is not. In the meantime, it is arguably a bug in Hibernate that it uses ClassLoader.getResources in a non-idempotent way - repeated URLs ought to be ignored.
*** Bug 195374 has been marked as a duplicate of this bug. ***
Why does "src/main/resources" need to be on the classpath? Why can't you scan the path using normal File handles? Also, I don't see why compile-on-save should be linked to "run tests directly". I want the former feature but don't mind disabling the latter feature (In my experience, Maven's test runner is fast enough).
(In reply to comment #3) > Why does "src/main/resources" need to be on the classpath? So that Class.getResource from a test would return something. > I don't see why compile-on-save should be linked to "run tests directly". > I want the former feature but don't mind disabling the latter feature This is an oxymoron; CoS _means_ running the app or tests directly. Perhaps you should read the CoS FAQ item. > In my experience, Maven's test runner is fast enough. Then turn off CoS.
To me, Compile on Save means that every time I save a file in the editor Netbeans will update error annotations as if the file had been compiled. You're commenting on specifics of the current implementation which I am not aware of. I'm wondering whether it would be possible to implement the same functionality in a different way. From a bird eye's point of view, how Netbeans locates a project's source files (to implement this feature) shouldn't affect the project's runtime classpath.
(In reply to comment #5) > To me, Compile on Save means that every time I save a file in the editor > Netbeans will update error annotations No, that always happens for any Java source file being edited, regardless of any project settings. "CoS" in NB means "use internally compiled classes to run/debug/test the program rather than spawning an external tool". The name is quite misleading but this is what our UI people chose. Again, please read the FAQ: http://wiki.netbeans.org/FaqCompileOnSave
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue. Thanks for your cooperation, NetBeans IDE 8.2 Release Boss