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.

Bug 195161 - maven test classpath includes src/main/resources
Summary: maven test classpath includes src/main/resources
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: PC Solaris
: P4 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords:
: 195374 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-02-08 09:34 UTC by mircea.crisan
Modified: 2016-07-07 08:37 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mircea.crisan 2011-02-08 09:34:09 UTC
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.
Comment 1 Jesse Glick 2011-02-08 15:16:13 UTC
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.
Comment 2 Jesse Glick 2011-02-14 15:29:20 UTC
*** Bug 195374 has been marked as a duplicate of this bug. ***
Comment 3 _ gtzabari 2011-03-20 13:52:21 UTC
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).
Comment 4 Jesse Glick 2011-03-20 23:27:15 UTC
(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.
Comment 5 _ gtzabari 2011-03-21 00:39:31 UTC
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.
Comment 6 Jesse Glick 2011-03-21 13:32:29 UTC
(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
Comment 7 Martin Balin 2016-07-07 08:37:19 UTC
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