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.
Hi, I have a "src" directory that is shared by two projects: One is a j2se project where I have a "test" directory to hold the JUnit test cases of "src", the other is a web project that uses the same java code in the "src" directory. (The reason is simple, 4.0 web project doesn't support JUnit test cases in a different directory yet.) In the j2se project, I overrode the "-post-compile-single" target in the "build.xml" file to do some formatting; in the web project, however, I have no such overriding. Ok, long way to raise the real question: When I open "My.java" in "src" directory from the j2se project, the "-post-compile-single" takes effect; when I open the same file from the web project, no "-post-compile-single" is done; so far so good! And now the problem: I now close "My.java" in the web project, and open it again from the j2se project, the "-post-compile-single" does NOT work any more!! What gives, and how do I handle this issue other than restarting the IDE? Any algorithm to determine which project's build.xml to use to perform targets like "-compile-single" is better than "random". My suggestion: *To perform any type of "single file" action, the share file should use the "build.xml" of the project under which it was opened in the IDE.*
You may never have one file shared among multiple projects under any circumstances. Probably in this circumstance you should have kept all sources and tests in the j2seproject and just imported the JAR into the web project, but I don't know for sure - would depend on exactly what you are doing. The choice of which projects "owns" a file is not random but it may depend on which order projects were loaded in, in case two projects both using external source roots declare that they own the exact same source root.
"[snip]... in case two projects both using external source roots declare that they own the exact same source root." Q: So in this case, if "My.java" resides in that same source root owned by both project 1 and 2, and I open it from project 1, and do a "-compile-single" on it, which project's build.xml will be used - Since both project 1 and 2 own the same source root? If it's not random, what exactly determines this?
As I said, the order in which the projects were loaded; currently the second project to be loaded "wins" control of the external source root. But this is only applicable in case both projects try to register the exact same external source root - in case one project registers a more specific (lower) root, it will be given preference and will own all files beneath that point.
"As I said, the order in which the projects were loaded; currently the second project to be loaded "wins" control of the external source root." Thanks that is exactly what I need to know! "But this is only applicable in case both projects try to register the exact same external source root - in case one project registers a more specific (lower) root, it will be given preference and will own all files beneath that point." Again, very precious info! For now I have to share exactly the same src root between a j2se and a web project instead of having the web one depends on the other: I need the JUnit support to the src root in the j2se project; and same time need the taglib class generation support from the web project; and it seems sharing the same src root is the only option.
"As I said, the order in which the projects were loaded; currently the second project to be loaded "wins" control of the external source root." I just checked with dailybuild 20041024, and it is NOT the case: I opened "My.java" from project 1, and project 1 "wins" of course; I closed and opened "My.java" in project 2, and project 2 "wins" (so far so good); now the problem: I then closed all files and restarted the IDE, opened "My.java" from project 1, and project 2 still "wins"! Am I missing something here?
With regards to your particular problem with JUnit etc. - I am sorry I cannot help more but I only know a little about about web apps; not enough to know what goes on with taglibs in detail. Or you may be able to just keep unit tests in the j2seproject, and add the web app's compiled classes to its classpath; should be able to unit test them just fine in this way. (Just don't have any ${src.dir} in the j2seproject at all.) With regards to loading order of projects after an IDE restart - I said *loaded*, not *opened* (all opened projects are loaded but not vice-versa). The IDE may be loading Project 2 (before 1) e.g. as part of the File -> Recent Projects list, etc. In short, the load order is technically deterministic but it may not appear to be from a user perspective due to the many ways in which a project may be silently loaded as a result of some user action. This is not normally relevant since sharing files among several projects is not supported (considered a user configuration error) - may be better reported / diagnosed in a future release.
I was hoping that I would not have to organize my code to conform to netbeans requirements. My web projects all share many of the same java source code. Unless I completely reorganize my source code and the way I place things in the CVS repository, separating the source code out so there is no crossover is just not possible. I understand that there are challenges in deciding who owns the project, but I think they can be solved. For instance, one solution about who owns the project, could be solved by letting the project whose source directory the file was opened from own the file. If this is not fixed, then at the very least it should be possible to make a web project with no java soure directory. I guess a bogus one could be created as a work around, but we should tell it like it is and not force the source directory. Also something should be done in the editor in the form of a warning or something to prevent this from happening. This is an issue for several people, so it should be addressed in some manner. See message thread: Weird things happen with multiple web projects
It is a fundamental aspect of 4.x design that projects cannot share files, period. Re. having a web project w/o any Java source dir - perhaps make sense, but I don't know anything about it, so please file an RFE with an example and some justification in the web/project component. Re. warnings - we already have open issues to detect potential overlaps at project open time and refuse to create ambiguous situations. Did not have time to do it for 4.1; still pending.