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

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

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.

Include a Netbeans Maven project in a Netbeans Ant project

I have a Netbeans Ant project that uses a Jar file generated from a Netbeans Maven project. I would like to "include" the Maven project directly in the Ant project to be able to proper debug both projects. The Maven project was converted from an Ant project and before the conversion this include was possible. I have control over both projects, but converting the Ant project to a Maven project is not really an option at this point. What is the best approach to make an Ant based project and a Maven based project "work" together i Netbeans?
Thanks
it should work if your ant project includes the maven local repository jar as dependency. Maven support does automatic binary->open project source conversion for local repo artifacts.

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

In eclipse, maven dependencies are overriding project dependencies

I have a "master project" that uses several "modules". The modules are in the pom.xml, but I also have the code for the modules as projects in Eclipse. I defined the modules as project dependencies both in "Properties|Project References" and in "Properties|Java Build Path". I also made sure all of the Eclipse projects are at the top of "Order and Export" in Java Build Path.
The master project is not recognizing changes to the modules within eclipse. When I press F3 to see the code, it opens java source from my .m2 directory. It's obviously ignoring my Eclipse projects. Am I missing some setting? What should I do?
You don't need to add the dependent projects into the Project references (at least when using m2eclipse-plugin), just add them as dependencies on your masters' pom.xml. I haven't had the need to touch the Build path since I've started using Maven in Eclipse.
Make sure you have enabled the Workspace resolution of the plugin by right clicking on project root -> Maven -> Enable Workspace Resolution. If it says "Disable Workspace Resolution", it is already enabled. You may also need to run "Update project configuration" under the same menu.
This way when you run your master-project from within Eclipse, any changes made to the other projects will be "visible" to the master (and you can actually use hot swap during runtime even on the other projects).
If you're using Maven, you pretty much want to commit to Maven. Even if you do configure Eclipse with Eclipse-specific dependencies, anytime you update your project configuration using Maven, it will do a complete rewrite of your configuration.
I strongly recommend converting any of your other project build dependencies into Maven-enabled projects that can be used as Maven dependencies.
In your specific case (through using the Maven modules), this means ensuring that each of your modules are imported into Eclipse as m2e-enabled projects. m2e will then automatically wire in the dependencies between modules and other dependent projects.
Im scratching my head as to why you would need your modules defined as dependencies on your top level project. Are you trying to avoid having to define the (cross) dependencies at a module level? In any case, as per other suggestions, first of all put your dependencies in the correct places in your POM, then either run
mvn eclipse:clean eclipse:eclipse
to update your Eclipse settings, or better still, make sure m2eclipse is installed and import your maven projects directly into the IDE.

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