Get jars defined in pom.xml - java

I have received a J2EE project which has some servlets defined.
I have imported this project in Eclipse [Version: Mars Release (4.5.0)] as a Java project.
This project has a pom.xml defined which contains a list of dependencies. How can pull the dependencies defined in pom.xml.
When I open pom.xml it opens as a raw xml.
Do I need to import this project as a Maven project?

If you have the m2e plugin (http://download.eclipse.org/technology/m2e/releases) installed into eclipse , you can import the project as a maven project and then run the dependencies by running as a maven build. Guess that will be the easiest to do.

Related

Maven Eclipse plugin, WAR overlays, and dependencies on project vs. Maven repo

I have a Maven web project that depends on other projects that build WAR targets, and then uses the other web projects as overlays. All of these projects are part of a single parent project, imported into Eclipse as a Maven project.
The main web project's POM has dependencies and overlays with maven-war-plugin defined for the other modules.
My problem
in Eclipse, for some reason, when I update the Eclipse project from the Maven project, some of the modules are recognized as coming from other Eclipse projects, and others are expected to come from my Maven repository.
On closer inspection org.eclipse.wst.common.component shows a difference in the dependent-module for some modules.
<dependent-module ... handle="module:/overlay/prj/module1" />
vs.
<dependent-module ... handle="module:/overlay/var/M2_REPO/group/id/module2" />
Why would some modules be recognized differently than others?
Both are equally included as dependencies and overlays in the POM.
My workaround has been to edit this file by hand to get Eclipse to recognize that it should use the other Eclipse project directly (module:/overlay/prj) rather than look to the Maven repo.

Making Eclipse play well with JPMS and Maven

Given a Maven project created in Eclipse from archetype maven-archetype-quickstart ( with junit upgraded to 5.5.2, which has JPMS support) , how can it be modularized to a JPMS project and still behave well in Eclipse?
When I tried this, I first created the module folder in the java folder and moved the package structure into that. The project structure then looks like this:
jpms (project folder) -> src/main/java/org.myorg.mymodule/org/myorg/myproject/jpmspackage
. So far so good. The project builds with mvn clean install in console and the unit test is executed. Then the module folder (containing the module-info.java file + packages) was set to source folder ("use as source folder" in Eclipse).
Performing a Maven build in Eclipse now fails with
Cannot nest'jpms/src/main/java/org.myorg.mymodule' inside 'jpms/src/main/java'. To enable the nesting exclude 'org.myorg.mymodule/' from 'jpms/src/main/java'
How can the source folder or build path be set to appease Eclipse?
Module descriptor:
module org.myorg.mymodule {
requires org.junit.jupiter.api;
}
Updated JUnit dependency (the project was originally generated with JUnit 3-something)
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
</dependency>
Versions: Eclipse 2019-09, Java 12, Maven 3.6.2
Keep the project structure, just add the module-info.java file into the default package:
Right-click the project folder and choose Configure > Create module-info.java
Please note, that for each module a separate project is required as it does not make sense to have multiple modules (which have different dependencies) in one project (if required, use nested projects instead).
See also this Java modules Maven example.

Eclipse Maven: How to build the added dependency first from the project itself?

I am using Eclipse with m2e plugin.
The steps I followed are as follows:
1. Created a sample Maven project
2. Imported an another Maven project in same workspace
3. Used imported project as dependency in my sample project
Now the problem is that since the imported project is not built and does not have target jar file, the sample project is showing error(jar not found).
So the question is it possible to run the build from sample project, which will build the dependency first, which in turn will be used in sample project build?
Run sample project build -> Build dependency -> Create dependency jar -> Dependency jar used in sample project build further
If this is possible, then how to do the same?
Thank you for any suggestion/feedback. :-)
m2e has a feature named Workspace Resolution that can be enabled/disabled for every project (right click on the project in the project explorer, then Maven). This allows you to directly use the classes of another project that you declared as dependency.
Note that is only works if your dependency (in your POM) and the other project have the same coordinates, including version number.

Does maven import option in intelliJ imports jars from remote repositories as well

Hi I am trying to build maven project using intelliJ.
I wanted to know what the maven import option does?
Apart from importing files from local repository and remote maven repository, does it imports/ updates files from SVN repository (which I am using).
So do I need to checkout the code from repository everytime or import option does this ?
Thanks
The maven import functionality in IntelliJ works as follows:
If you want to use an existing Maven project, you can import it directly by opening its pom.xml file. When a Maven project is imported, it maps to an IntelliJ IDEA module with the name, which is equal to the Maven project's artifactId. Dependencies between the Maven projects map to the dependencies of IntelliJ IDEA modules from the libraries and other modules. IntelliJ IDEA analyzes the pom.xml file and automatically downloads the necessary dependencies.
It will not checkout code from your SVN repository. Maven is a build tool that helps manage dependencies that your package may have, while SVN is a version control system that is meant to track changes you make to code.

Integrating a maven project into Eclipse

I have a maven module for validation which I must pass to a old version of Eclipse which has the Jrules API within. However there is not a maven plugin for this eclipse IDE. So I figured I would do a maven:install on the module and move over the created jar.
However when I try to import->Existing Projects into Workspace->Select archive file:
and point it to the jar no projects appear. I'm at a loss as to how I can move my maven module to the outdated eclipse, without having to grab the 101 jars required for the project and non mavenise it...
Surely their has to be an easy way to this or is maven will monolithic
Use the maven-eclipse-plugin to generate the .project and .classpath files for you:
mvn eclipse:eclipse
This will create the IDE metadata files which reference all of the JARs your project depends on from within your local maven repository folder.
Attempting to import the JAR that is built by the Maven build process into Eclipse using the " import->Existing Projects into Workspace->Select archive file" doesn't work because Eclipse expects to find a .zip/.jar file with the .project metadata files and the source code. Your compiled JAR likely contains neither.
I would recommend using the M2Eclipse maven plugin. Right click the project -> Enable Dependency Management -> Update Project Configuration
I have used eclipse:eclipse extensively and my experience is that M2Eclipse is not only better supported but works better overall.

Categories

Resources