13

Using Eclipse that was being used prior on the project by another developer. Most things are flagged as red and broken. Seeing files in src/main/java/... and the same exact files over in java resources/src/main/java...

Just confused over what is what, what is temp, what to keep to trash or how to fix the project environment.

Any easy fix to this?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
edjm
  • 4,830
  • 7
  • 36
  • 65

3 Answers3

11

There's no standard for anything at the root level called resources.

src/main/resources is normally where you put non-Java artifacts that should be moved into the normal package hierarchy, like XML config files loaded as classpath resources.

It's impossible to help much beyond that, other than to say "check your Maven file to see if anything actually references those files", particularly if anything generates files to there, or moves them there as part of an assembly process, but again, that would be non-standard Maven usage.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Are all the files present in the resources folder added to the Classpath by default? – Sen Aug 22 '18 at 19:45
  • 2
    "`src/main/resources` is normally where you put non-Java artifacts that should be moved into the normal package hierarchy, like XML config files loaded as classpath resources." Yes, they're moved into the normal package hierarchy. – Dave Newton Aug 22 '18 at 19:48
  • @DaveNewton - My course has a sample app as a jar file. I'll be writing automated tests for that app. Is it okay to put the app.jar in the src/main/resources directory ? – MasterJoe Aug 05 '20 at 18:30
  • @MasterJoe What? You can put anything you want in there; whether or not you *should* depends on what you actually want to *do* with it. What you're asking is an *entirely* different question than this one from 6 years ago. – Dave Newton Aug 05 '20 at 19:23
5

Your question's has multiple answer since they already exists everywhere and easy to get them I am just pointing you to them with links and little description.

What is Maven ?

  1. Maven is a build tool,it helps to manage dependencies (jars) easily and efficiently.
  2. Maven does everything what ANT can do,even it has plugin to do some specific ANT activities.
  3. Very easy to migrate from third-party library.
  4. Unit testing also bit easy to configure,overall configuration is very simple.

For more information -> http://maven.apache.org/what-is-maven.html

Why Maven ?

https://stackoverflow.com/questions/1077477/why-do-so-few-people-use-maven-are-there-alternative-tools

Why resources directory ?

Before maven exists we used to have resources package within application,which will actually contain some application configuration properties file,Internalization property files , XML files (basically non java files which are required for application run-time ).

One case study i were been using Resource directory

In our company we wanted have different property values for development,staging, pre-production,production environment.So we had four directories and Resources folder saying environment name.Each directory will contain its own property files and properties.During maven build we should mention which profile is this build for ?.Based upon that only specific resource files are loaded in the deployment assembly.

More information about profile in maven -> http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Eclipse error's solving

And your eclipse is having red flags you need to fix the build path issues,if it gets the respective source code.Red flags will be vanished.Since you didn't mention what errors you are seeing i am placing general discussion on build path fixing - > Problem with Java Buildpath in Eclipse

Bikash Das
  • 147
  • 1
  • 12
prem
  • 843
  • 1
  • 8
  • 21
2

Go to your Project folder e.g. MyProject in command Prompt

run below commands one by one (assuming you have installed maven in your system)

cd  C:\MyWorkSpace
cd  MyProject
mvn clean install -DskipTests=true
mvn eclipse:eclipse

and then right click your project and click Refresh

That might solve your problem.

DeepInJava
  • 1,871
  • 3
  • 16
  • 31