What is the purpose for the resource folder in Mav

2019-04-26 15:32发布

问题:

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?

回答1:

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.



回答2:

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



回答3:

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.