Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't understand your problem. Resources from <code>src/main/resources</code> are automatically copied over to <code>target/classes</code> and are thus available on the classpath under Maven and Eclipse relatively to the root level at the same location (unless your Eclipse project is not properly configured). </p> <p>And when packaged inside a JAR, the content of <code>target/classes</code> is packaged "as is" so nothing is changed. </p> <p>In other words, accessing your <code>file.txt</code> like this is perfectly fine (and this is actually <a href="http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR" rel="noreferrer">how things are documented</a>):</p> <pre><code>// Retrieve resource InputStream is = getClass().getResourceAsStream( "/file.txt" ); // Do something with the resource ... </code></pre> <p>If you have a problem somewhere, please clarify.</p> <p><strong>Update:</strong> I did a quick test with the maven-eclipse-plugin and I can't reproduce your problem:</p> <pre><code>$ mvn archetype:generate -DgroupId=com.stackoverflow -DartifactId=q2467362 -Dversion=1.0-SNAPSHOT ... $ cd q2467362 $ mkdir -p src/main/resources $ mvn eclipse:eclipse ... $ cat .classpath &lt;classpath&gt; &lt;classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/&gt; &lt;classpathentry kind="src" path="src/main/java" including="**/*.java"/&gt; &lt;classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/&gt; &lt;classpathentry kind="output" path="target/classes"/&gt; &lt;classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/&gt; &lt;classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/&gt; &lt;/classpath&gt; </code></pre> <p>The directory <code>src/main/resources</code> is added as source folder as expected. Can you show your POM (especially the <code>resources</code> element if you define one)?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload