Community
Participate
Working Groups
I keep separate source and test class trees in src and test folders respectively. The test classes have to find various resource files that are located in the root test folder. They do this using a class loader getresource () method which will find the files if they are anywhere on the class path. This all worked just fine when the classes were compiled to the source folders. But when I tried to compile classes to a separate output folder it quit working. Apparently the output folder is added to the classpath, but the original source folder is not. This would be fine if I could add the original source folder as a class folder on the Properties | Java Build Path | Libraries tab. But when I try that it complains that classpath contains a duplicate entry and won't accept it. The JDT either needs to include both the source and output folders in the class path, or allow me to manually add the source folder to the class path.
Source folders are meant to contain sources. You can have them be an output as well, as you already know. If you separate their output, then they won't appear on the classpath at runtime. This is why the resources in there are copied also into the output automatically (except for .java files which are considered as sources, thus only generated .class files are necessary at runtime). If you want to have .java resources available at runtime, then you should store these into a class folder. It will be appended to the runtime classpath. Does this work ?
If the resource files got copied to the output folder everything would be cool. But this isn't happening. Is there something I am supposed to do to declare them as resources? It makes sense that the source folder wouldn't automatically be added to the classpath, but I should be able to manually add it as a class folder in library tab without it complaining that it is a duplicate classpath entry.
Well, we don't want the same thing to be made available twice. First, are these resources Java files or not ?
The files in question are not .java files. They are pretty much all XML files with a .xml extension.
Problem solved. Eclipse is copying all of the resource files when I ask it to build the project. My problem was that I was trying to run programs without building them, not realizing that it wasn't going to go through the build process first. It found the compiled classes just fine because I had built them with an Ant script, but the Ant script put the original source folder on the path rather than copy the resources to the class folder. So test programs ran fine under Ant, but not under Eclipse proper.
Reopening to mark as invalid (no action was taken from the JDT Core team to fix this problem)
User error.