Note that there are some explanatory texts on larger screens.

plurals
  1. POMaven - Load resources from JAR?
    text
    copied!<p>I have a feeling I'm missing something critical when it comes to bundling resources in JAR files using Maven. My directory structure is the standard Maven one (i.e. \src\main\java, \src\main\resources).</p> <p>When using the IDE I reference the resource files as \main\resources\images\blah... and it works fine, but when Maven bundles the JAR file it puts the paths relative to the root ("\images\blah"), so none of the paths are correct. </p> <p>My question is two-fold really, the first being am I missing something obvious? The second being what's the best way to handle this issue? I know I could just replace all the paths when I go to bundle everything for deployment, or surround all the paths in try/catch blocks, or even change the maven output directory, but I feel like these are in-elegant and I'm missing something. Thanks in advance.</p> <p>EDIT: I reference the resource files like this: <code>getClass().getResource("/main/resources/images/lightboardImage.jpg"));</code></p> <p>EDIT2: This is obviously now an IDE configuration issue, probably stemming from the fact that I converted an old project into one using Maven. I don't really understand how it is misconfigured though. My folder structure is:</p> <blockquote> <p>src/main/java<br> src/main/resources</p> </blockquote> <p>My classpath has one entry for "src" <code>&lt;classpathentry kind="src" path="src"/&gt;</code></p> <p>If I right click on the <code>/main/resources/images/</code> folder and Use as Source Folder it turns the classpathentry into this <code>&lt;classpathentry excluding="main/resources/images/" kind="src" path="src"/&gt;</code> and creates a new one like this <code>&lt;classpathentry kind="src" path="src/main/resources/images"/&gt;</code>. It also doesn't work.</p> <p>EDIT3: Okay this is really dumb but I just realized what the issue is. I'm not actually using Maven for local development builds. It's using Eclipse's built in Ant configuration or whatever. Maven is used for the automated deployment builds, hence the issue. Sorry to waste everyone's time.</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