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

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

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.

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

Idea IntelliJ. how creating maven project. what about pom.xml and .iml files

i just started with java, and created a project.
its maven project (i hadn't use maven yet)
so my project have two modules A and B.
and B depends on A, and A depends on some from remote maven repo. and B also depends on some remote repo.
its works fine in Idea IntelliJ and build jars fine.
but afaik .iml files are Idea IntelliJ specific. and pom.xml is maven specific.
and when i inspect files why all depedecy of project is written in .iml files and .idea dir instead of pom.xml(s)
if you want to see the real world source then here it is but its alpha project for learning java deeply.
and when i try to build project on travis-ci.org it unable to resolve dependencies of project
Meghraj,
I have forked your WebTrimmer repo here : https://github.com/ajorpheus/WebTrimmer and fixed a couple of issues which were preventing a successful build:
The travisci fails because you have three jars in the lib folder which are not available to the CI since it's doing a maven build. The fix was to remove those three jars and introduce corresponding maven dependencies as in this commit.
While adding the maven dependencies an exclusion was needed as noted here : The following artifacts could not be resolved: javax.jms:jms:jar:1.1
The WebTrimmerUI depends on the classes in it's sibling module WebTrimmerEngine, therefore a corresponding dependency is needed.
I have converted the project into a pure maven project which is IDE-agnostic. With the above changes, I can build the project from command line and expect that the travisci should be able to as well.
Regarding the question about why the dependencies are duplicated in .iml --- That's not the reason the CI job fails. The dependencies in that file are a snapshot of the dependencies in the pom.xml. This snapshot is updated when the maven project is re-imported manually by the user, or automatically if the maven project is set to 'Auto-Import'.
As Peter Lawrey mentioned in his comment above, if you add a jar to the project, maven does not know about it and it will be present only in the .iml file.
In general, to search and add a maven dependency, the following has always worked for me: https://stackoverflow.com/a/10178586/325742
Hope this helps !
You need to add dependencies to the pom yourself. The .iml files are for storing project specific settings for whatever project you are currently working on.
Having the pom files allows your maven builds to be IDE independent where as the .iml files require you to have IntelliJ.
You can exclude the .iml files from and version control you are using. You can also open an existing maven project directly via IntelliJ by opening its pom.xml and IntelliJ can auto import everything specified in the pom file and will generate new .iml files.

Problems with classpath and resources

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.

Categories