Deploy Artifact to Nexus from Eclipse - maven

Is it possible to run mvn deploy from Eclipse using M2E? I have the distributionManagement section in my pom.xml and the server configured in my settings.xml, but I can't for the life of me see where I can fire of that specific goal.

If the distributionManagement section of your pom is setup properly and pointing to your Nexus, you just need to run the Maven
deploy
goal.
Assuming that you installed the m2eclipse Maven Eclipse plugin, right click your project or your pom, Run As>Maven build and enter the goal "deploy" on the goals line.
If you did not install a Maven Eclipse plugin, add an External Tools configuration pointing to your Maven install for its "Location" and your project dir for its "working directory", with "deploy" as its argument.

Related

Maven - do a mvn install on local artifact when packaging

i have a maven project which has some local artifacts as dependencies.
When I have to package my main application, i have to do a mvn install command on my local repositories before, which is quite annoying and easy to forget.
Is there a way to tell maven to install local repositories when packaging the main one?
One solution can be to wrap up all your components into a pom project.
When building a parent pom maven automatically triggers a build of all the sub-modules.

How non maven project can be added as a dependency in maven project

One project A is added in project B as a source.
I want to add in POM.xml of project B.
1-A is non maven project.
2-B is Maven project
How non maven project can be added as a dependency in maven project as a dependency.And I don't want to run it as a separate project and place the jar in local repository.
You need to put the "non-maven-jar" into the local (or a remote) repository. You can either build it and use mvn install:install-file to install it locally (or the deploy plugin to use a remote repository) or you need to change project A into a Maven project.
Technically, it is also possible to include a dependency by a path (<systemPath>), but this is not recommended.

Installation and deployment of maven test-jar

I've discovered the wonderful test-jar facility in Maven: https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
But it may so happen that one project needs to use the test-jar of another project. From https://stackoverflow.com/a/6469256/421049 and experimentation, it would seem that using mvn install does not install the test-jar to the local ~/.m2/repository. So how does one project on my machine use the test jars of another project not in the same aggregate POM?
Yet it would seem from Maven deploy not to upload test jar that deployment of a project to Maven Central does in fact deploy the test-jar? So I can deploy it to Nexus but not install it locally? And if I deploy it to Nexus, will my local project using a dependency of <type>test-jar</type> go find it on Maven Central?
It turns out that maven-jar-plugin does in fact install the test-jar (e.g. foo-1.2.3-tests.jar) in the local Maven repository ~/.m2/repository/.... Wonderful!
My problem is that I had inadvertently configured the maven-jar-plugin to be in a separate profile named release. (I had copied and pasted to the wrong location in my POM.) That's why the test-jar didn't show up in my local repository after a mvn install, and that's why it suddenly showed up later (after I used -P release once in testing), and I thought I had just missed it when I looked the first time.
I move the maven-jar-plugin to the <build> section and everything is working fine: the test-jar gets put into the local maven repository using mvn install.
In my case, I was setting maven.test.skip for a particular build profile. That property actually causes tests to not be compiled/installed, thus also preventing their deploy. The solution was to set the skipTests property instead.

Do we have to include jar files in eclipse project if we are using maven?

I am new to maven.
The POM file in maven contains all the dependencies that we need in our project.
So we don't have to externally add any JAR's to the buildpath in eclipse.Right?
That's right. Maven will download dependencies and M2Eclipse (Eclipse plugin for integrating Eclipse with Maven) will setup a build path for you.
Two Solutions - 1 Using Eclipse IDE
Install the Maven (M2E Eclipse Plugin) if you use older version of eclipse, If you download the latest eclipse.
Point your settings.xml and create a maven project from your eclipse, it is better keep Group Id as com.yourcompany.app Artifact Id as yourProjectName and Version 0.0.1-SNAPSHOT depends on your Architecture Standards set by your company. Also Packaging can be as WAR file for WebApplication, EAR file for Enterprise Application. You can find the numerous list of examples from Maven Site.
2 From Command Line
Install Maven from Apache Maven site, Would recommend to go for the latest version -apache-maven-3.3.9-bin.zip.
Set the Maven Home in the Environment Variables as shown in the below figure.
Edit Your Path variable as %MAVEN_HOME%\bin, verify your installation by using this command from your command prompt. It should display the Maven Home and Java Version, which confirms your maven successful installation.
Paste your settings.xml (C:\apache-maven-3.3.9\conf) given by your build team or Architecture team for accessing your internal repository. And keep a backup of the original settings.xml (which is default download from Maven site)
Run these commands from your command prompt.
mvn eclipse:clean -e
mvn eclipse:eclipse -e (which will automatically set your project build path as shown in the below figure)
It will resolve your compilation issues and your project is ready as an deploy-able artifact

maven install-file "Missing artifact"

I want to reference a jar (ie vim25.jar, VMWare VSphere server management) in the POM of my project. As this file is not referenced in MavenRepository I do the following steps:
Download the file from VMWare site
Install the file using:
mvn install:install-file -Dfile=./vim25.jar -DgroupId=manuallyInstalledJars -DartifactId=vim25 -Dversion=2.5 -Dpackaging=jar
Everyting works well and I can find the jar in myLocalRepo/manuallyInstalledJars/vim25/2.5/vim25-2.5.jar
Beside the jar there is the POM, I open it and extract the dependency references:
[groupId]manuallyInstalledJars[/groupId]
[artifactId]vim25[/artifactId]
[version]2.5[/version]
("<" replaced by "[" because of the editor)
I enclose this with the [dependency] tag and put everything in the POM that uses the jar
In Eclipse I get an error (red mark in the text editor) with this comment:
"Missing artifact manuallyInstalledJars:vim25:jar:2.5"
Any idea ?
Perhaps just post the dependency xml so we can rule that out.
In any case try this in Eclipse (assuming you have m2eclipse plugin installed)
Window-> Show View -> Maven Repositories
Expand Local Repositories
Right click Local Repository -> Rebuild Index.
This sometimes help refresh the maven repo in Eclipse when youve made external changes
After the rebuild, check you can see the JAR in that local repository tree in the maven repositories view. You can also confirm that Eclipse is looking at the same local repository as your external maven installation.
If it's not, check the user settings in the eclipse preferences.
Window -> Preferences -> Maven -> User Settings
You can check it is referencing the correct maven settings xml file

Resources