Problems with classpath and resources - java

I have a project that has 5 modules (I'm using maven)
In my module A I have 2 source folders: src/main/java and arc/main/resources
In my folder src/main/java I have a simple App.java (console app) that when I try to Run As -> Application in Eclipse doesn't find anything in my resources folder.
It doesn't find my log4.properties (which is in src/main/resources/log4j.properties) and it doesn't find a resources file app_es_ES.properties (wich is in src/main/resources/app_es_ES.properties)
How can I set my app to find in the resources folder my properties files? Could it be a problem with maven? Should I run my app in a different way?

You have to configure your eclipse project to match your maven configuration. This can be accomplished by either using the
maven eclipse plugin - mvn eclipse:eclipse to generate the eclipse project artifacts. Then import the generated project into the workspace.
m2eclipse eclipse plugin - much nicer (IMHO) as it integrates your maven and eclipse workspace. Thus your pom is used to manage your dependencies and eclipse .project and .classpath is kept in sync with maven.

Related

Unlink project as a maven dependency of another project in Spring Tool Suite

I have some projects with many json files that when compiling them with maven generate many java bean classes and I have a main project that has the maven dependency of these other projects. Well, if the other projects are closed, when updating the maven dependencies it gets the compiled projects in my .m2 folder and the main project does not show errors in STS, but, instead, the projects are open, STS changes that dependency from the .m2 folder to the open project, and it does not find the java classes in the source folder because they are in the target.
How can I tell STS not to use the projects that are named the same as the maven dependencies? This way I compile the projects independently from the console and update the dependencies to the main project when necessary.
Right-click on the project, select "Maven" and then "Disable Workspace Resolution". I do this for every project. I wish there was a way to set this as a global preference. I wrote a shell script that whacks on all the .settings files in my project to set this flag for all my existing projects.

Eclipse project and Maven pom file not in same directory

I have a project in Eclipse for which the Pom file(pom.xml) and Eclipse project file(.project) are not in the same directory. The Pom file is next to the source code.
The project resources in Eclipse are defined as Linked Resources(http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fconcepts-13.htm).
I added the pom file as a Linked Resource then and converted the project in Eclipse to a Maven project(Configure -> Convert to Maven Project).
Unfortunately Eclipse is not showing the Maven Dependencies for that project and these are not resolved. Just having the Eclipse project file next to the pom and resources works well for that project but I cannot eventually use it(it's a company rule).
Tanks a lot in advance for your help
Unfortunately Eclipse is not showing the Maven Dependencies for that
project and these are not resolved.
Yeah, and I believe that the Eclipse project files are not going to pick up your changes when you convert to a maven project. This is simply the way maven works because you have the .project file elsewhere.
One note may be helpful: it is generally considered bad practice to check in your .project & .classpath files into src control, no matter where they are located. Can you try and have those files removed from source control and generated for each developer locally.
Personally, I always do that when I first create the Eclipse workspace by creating my project from the pom file: File -> import -> Existing Maven Project and then I browse to the pom.xml file. My understanding is that this is (for many) the preferred way to create the java project in Eclipse.

what is the difference between maven-archetype-webapp and eclipse dynamic web project

why do I need to apply: mvn eclipse:eclipse command?
are they equivalent to application container/server?
Is there a file for which customizing is necessary besides web.xml?
when you create a web project using maven, like maven-archetype-webapp. It creates the folder structure as recommend by Maven for a webapp like shown here .
Now when you try to import these folders in Eclipse, it still would look like folders but eclipse cannot understand the nature of these folders. Eclipse relates folders and contents within them to an Eclipse dynamic web project only through its .project , .settings files
So in order for your maven project to be understood by Eclipse, you run the goal mvn eclipse:eclipse. After executing this goal, maven generates the .project, .settings files necessary for eclipse to understand the project as Web project.
This is however optional. You can still import the project as Maven projects within eclipse and continue to use them but you cant rely on Eclipse's features like clean/ build / build automatically.
Though I use eclipse, I dont rely on Eclipse's build feature. I have installed Maven eclipse plugin and that allows me to run maven goals and commands within Eclipse which is as good as running Eclipse's build feature. Hope this helps.

How to quickly replace a Maven Dependency with an Eclipse project?

I have setup a Dynamic Web Project in Eclipse using Maven. The Web Project has a lot of dependencies to other JARs. The JARs are properly added to the WEB-INF/lib folder in Maven/Eclipse. Many of the JARs though are results of other plain Java projects. I want to have the JARs represented by their resepective Java projects in Eclipse from time to time (but not for all of them).
So how do I quickly replace a normal Maven Dependency JAR by its Eclipse project?
Currently I:
Remove the Maven Dependency (Right click on the JAR, Maven -> Exlude Maven Artifact)
Edit the Build path and add the corresponding Eclipse project
Mark the project also in the "Export and Order" section of the Build path
Edit the Deployment Assembly properties and add the Eclipse project there as well (so it goes into WEB-INF/lib at runtime).
If your web projects is a maven project (little "m" in the upper left corner) and you have installed the M2E-WTP plugin (included in the Keplar JavaEE package), this will happen automatically, i.e. when the dependent project is open in the workspace, it will be a project link, if it is closed, your web project will use the jar file as dependency.
If you are using M2Eclipse, I gess you should enable Workspace resolution.
Both projects should be maven projects.
If you're using mvn eclipse plugin, make sure, they both have a pom.xml and call :
mvn eclipse:clean eclipse:eclipse

How to "add Maven nature" to existing netbeans project?

I know "adding Maven nature" is an Eclipse term.
Actually I want to add SOME dependencies from maven repository by editing pom.xml file. Is it possible? I want to remain a directory structure and other JAR tracking of a project intact.
The project is of jMonkey SDK.
in netbeans there are no natures. Either the project is a maven project (by having a pom.xml file in project directory) or it's not. No matter what type, projects are just opened.
if your project is both ant based project (having nbproject/project.xml file and build script) and contains pom.xml, then the ant project takes priority and will be opened as ant project. No way to mix then. to load as maven project you will have to delete ant project related files and restart the IDE.
add minimal pom.xml file
close project
re import it to netbeans as maven project
or create a new minimal maven project and delete source and resource directories and place your project stsructure and
configure pom.xml to match with your directory structure
by specifying resources & source directories in pom.xml

Categories