tags:

views:

42

answers:

3

Motivation

In eclipse I'd like to configure a path as a resource path. This path contains some java files that I only want to handle as resources, i.e. I don't want eclipse to try to compile these files. I only want to read them as resources from within junit tests.

Question

Is there a way to configure eclipse so it won't try to compile the java files it found there?

A: 

Check Included=All and Excluded=*/.java for the specific source folder in the Java Build Path through the Project properties.

alt text

Timo Westkämper
But then I won't be able to access the java files as resource anymore.
tangens
A: 

You can remove the folder from build-path:

  1. Right click on project -> Build Path -> Configure Build Path
  2. Select tab "Source"
  3. Remove the folder you want only to handle as resources

Eclipse won't compile Java files in that folder

Fede
But then I won't be able to access the java files as resource anymore.
tangens
Sorry, I think I don't understand your question. I have this sample project:http://i43.photobucket.com/albums/e372/nain_i/resources.pngAnd I can access files in resource folder from Main class: public static void main(String[] args) throws IOException { FileReader file = new FileReader("resource/com/stackoverflow/BeanTest.java"); BufferedReader reader = new BufferedReader(file); String line; while ((line = reader.readLine())!=null) { System.out.println(line); } }Hope this help
Fede
+1  A: 

You can specify excludes for *.java files in project properties / Build Path / Sources preferences. However in that case *.java won't be copied into the target folder, so those resources won't be available at runtime classpath. To get around that, after adding excludes you can add a custom builder (e.g. Ant script) that would copy *.java files over.

Alternatively, you can use m2eclipse with Maven-enabled project and place your java files into src/main/resources, so all files from that folder won't be compiled, but they will be copied into the result classpath.

Also, you can try to point target folder to the same dir as source folder.

Eugene Kuleshov
Good point about the resources. +1
VonC