Win a copy of Head First Go this week in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Jar file path question  RSS feed

Saloon Keeper
Posts: 9862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're happy you're happy, but if you're using Maven and you're mixing sources and resources and using unconventional directory structures, you're only setting yourself up for more problems down the line.

I can't tell you what to do, but I can advise you that you can fix now what doesn't seem broken before it gets too complex to fix when it IS broken.

I challenge you to the following, it shouldn't take much more than 15 or 20 minutes of work: Copy your entire project folder to a safe place, and then delete all Eclipse files and all generated files from your original project folder, so you're only left with a Maven POM and a src folder. Make sure that the src folder has the  following structure:

You life will become MUCH easier if you put resource files in a package with the same name as the package that the source files are in that will be using those resources. For instance, if you have a class com.example.gui.MainForm, you could have the following files:

  • src/main/java/com/example/gui/
  • src/main/resources/com/example/gui/some-icon.png
  • src/test/java/com/example/gui/
  • src/test/resources/com/example/gui/main-form-test-script.txt

  • Now, in Eclipse go to the File menu, click Import... and then browse to the Maven folder and select Existing Maven Projects. As the root directory, select the directory above your project directory, and Eclipse will find all Maven projects inside that directory. Select your project and finish the wizard. Eclipse will now create a completely new Eclipse project that has all the correct settings according to your Maven POM.

    In the <properties> element of your Maven POM, add the following element:

    In the <plugins> element of your Maven POM, add the following plugin:

    Now go to the Run button and instead of clicking it, fold it open and select Run As... > Maven Build... (with the ellipsis at the end. In Goals, enter clean install exec:java, and then when you run your project with this build configuration, it will build and run in with Maven, which is definitely what you want if this is a Maven project.
    Ranch Hand
    Posts: 114
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks. I'll give that a try.
    No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
    Become a Java guru with IntelliJ IDEA
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!