Install project artifacts to specific directory not .m2 - maven

I to install my project artifacts to specific directory rather than the default .m2 directory. How can I do this (where should I edit in the pom.xml file)

You can use the Maven Deploy Plugin's altDeploymentRepository parameter. It can be given from the command line, so it should not be necessary to edit the POM file. Here is an example of using it.
The relevant section is:
mvn clean deploy \
--batch-mode \
--errors \
-Psonatype-oss-release \
-Dgpg.keyname="$GPG_KEYNAME" \
-Dgpg.passphrase="" \
-DaltDeploymentRepository="staging::default::file:staging"

Related

Push Jar file instead of Zip using maven nexus

I am trying to push zip file using mvn deploy command. The command I am using is:
mvn clean -s settings.xml \
package deploy:deploy-file \
-Dfile=${ARTIFACT_ID}-${VERSION}.zip \
-Durl=${NEXUSURL}/repository/maven-${PKGREPO} \
-DrepositoryId=nexus-${PKGREPO} -DpomFile=pom.xml \
-DskipTests -Dpitest.execution.skip=true -Ddependency-check.skip=true
but I can find .jar file instead of zip?
Able to resolve after adding -Dpackage=zip.

Use WAR as dependency in Maven

I was given a project by a client that has a bunch of dependencies that are in a WAR file that they provided. I have added the dependency to the pom.xml:
<dependency>
<groupId>com.oragle.oipa</groupId>
<artifactId>PASJava</artifactId>
<version>10.2.0.25</version>
<type>war</type>
</dependency>
But clearly, as I physically have the files, they cannot be installed by Maven automatically. What can I do to get Maven to recognize their location and set them up for me?
If the war is not associated to a pom.xml, you should "mavenize" it to be able to use is as a Maven dependency in another Maven project.
1) You can look the install-file goal of the Maven install plugin.
It allow to generate and deploy the pom in your local repository.
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
With your example, you could generate and install the war artifact in this way:
mvn install:install-file -Dfile=locationOfYourWarFile -DgroupId=com.oragle.oipa
-DartifactId=PASJava -Dversion=10.2.0.25 -Dpackaging=war
2) You can also look at the deploy-file goal of the Maven deploy plugin.
It allows to generate and deploy the pom in a remote repository. It may be useful if other users need the war as a Maven dependency.
http://maven.apache.org/plugins/maven-deploy-plugin/usage.html
Here is an example from documentation :
mvn deploy:deploy-file -Durl=file://C:\m2-repo \
-DrepositoryId=some.id \
-Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=test] \
[-DgeneratePom=true] \
[-DgeneratePom.description="My Project Description"] \
[-DrepositoryLayout=legacy] \
[-DuniqueVersion=false]

Maven create a project without sources

I'm currently trying to deploy a third party jar and 2 dlls to a private artifactory.
I don't have the sources for any of these artifacts. I could install these artifacts manually trough mvn install:install-file but I would have to manually do that every time the jar or dlls are updated.
I was trying to achieve a solution that allowed me to deploy with mvn deploy.
I was thinking about creating a maven project with these 3 artifacts or a parent maven project with 3 child project as dependency. What is the best way to create a maven project in this case where I have no source to compile and put in a jar file?
If you have the case where you three files belong to the same project which means jar file needs the dll's you should deploy them as a main artifact (jar) and supplemental artifacts (classifier) for the dll's which can be achieved by something like this:
mvn deploy:deploy-file \
-DgroupId=com.soebes.test \
-DartifactId=t1 \
-Dversion=1.0.1 \
-Dpackaging=jar \
-Dfile=t1.jar \
-Dfiles=t1.xml,t1.pdf \
-Dclassifiers=xml,pdf \
-Dtypes=xml,pdf \
-Durl=http://localhost:8081/nexus/content/repositories/releases \
-DrepositoryId=releases
Where file= is the main artiact and files=... the list of artifacts. The classifier is given for every artifact in the list given via files=....
The repositoryId is needed if you have authentication for your repository manager.

install maven archetype project jar with *.pom file to local repo

i`m kinda new to maven and want to know how to install an archetype jar to my local repo
i got a directory com.foo with the following files:
maven_metadata_local.xml
[1.00.00-SNAPSHOT]
which containes these files
_maven.repository
foo-archetype-1.00.00-SNAPSHOT.jar
foo-archetype-1.00.00-SNAPSHOT.pom
maven_metadata_local.xml
from what i read i understand that there is a way to build a template project using this archetype but first i need to install it to my local repo
how can i do this?
thanks
i managed to do that:
what i did is opened the maven_metadata_local.xml to get the groupId, artifactId, and version
run this command from that directory
mvn install:install-file
-Dfile=foo-archetype-1.00.00-SNAPSHOT.jar \
-DgroupId=com.foo \
-DartifactId=foo-archetype \
-Dversion=1.00.00-SNAPSHOT \
-Dpackaging=jar \
-DgeneratePom=true
once compleated (BUILD SUCCESS) i got the build in my local repository
go to a folder from which i want to create a project
run this command
mvn archetype:generate \
-DarchetypeGroupId=com.foo \
-DarchetypeArtifactId=foo-archetype \
-DarchetypeVersion=1.00.00-SNAPSHOT \
-DgroupId=com.mycom \
-DartifactId=myApp \
-Dversion=myversion-SNAPSHOT
in eclipse i imported an existing maven project, right click on the project->maven->update
and i got the full build ready to work
Adding an archetype to your local repository is no different than adding any other dependency. You can simply run a mvn install command on it.

How to add a jar, source and Javadoc to the local Maven repository?

I'm wanting to add the latest version of JGoodies Forms (1.5.0) as a dependency, but I can't find anything newer than 1.0.5 in the main repository, so if I understand correctly, the next best thing I can do is add it to my local repository.
When I download it from the website, I get a ZIP file that contains the javadoc files, the source code and the jar (with just class files in it).
What is the procedure for adding this to my local Maven repository in such a way that Eclipse will be able to see the source and Javadoc? (I've only just started using Maven)
Update: Even though this is the accepted answer, please check the answer of Emmanuel Bourg below - his answer is probably what you would like to do, especially if you're having a snapshot version.
You can use the maven deploy plugin for that. It has a goal for deploying a single file to any repository.
For the jar itself:
mvn deploy:deploy-file \
-DgroupId=com.yourname.jgoodies \
-DartifactId=jgoodies-forms \
-Dversion=1.50 \
-Dfile=/path/to/jgoodies-1.50.jar \
-Dpackaging=jar \
-Durl=file://path/to/your/local/repository
For the sources:
mvn deploy:deploy-file \
-DgroupId=com.yourname.jgoodies \
-DartifactId=jgoodies-forms \
-Dversion=1.50 \
-Dfile=/path/to/jgoodies-sources.jar \
-Dpackaging=jar \
-Durl=file://path/to/your/local/repository \
-Dclassifier=sources
For the javadoc:
mvn deploy:deploy-file \
-DgroupId=com.yourname.jgoodies \
-DartifactId=jgoodies-forms \
-Dversion=1.50 \
-Dfile=/path/to/jgoodies-javadoc.jar \
-Dpackaging=jar \
-Durl=file://path/to/your/local/repository \
-Dclassifier=javadoc
Note that this will generate a standard POM, so you won't have the dependencies of JGoodies (if any) pulled automatically but have to specify them manually in your project.
Here is the syntax to deploy the binary, the sources and the javadoc with a single command:
mvn deploy:deploy-file \
-DgroupId=com.jgoodies \
-DartifactId=jgoodies-forms \
-Dversion=1.6.0 \
-Dfile=jgoodies-forms-1.6.0.jar \
-Dsources=jgoodies-forms-1.6.0-sources.jar \
-Djavadoc=jgoodies-forms-1.6.0-javadoc.jar \
-Durl=file://path/to/your/local/repository
Install the jar you have downloaded using this mini guide :
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
You should install jgoodies-form-1.5.0.jar by typing:
mvn install:install-file -Dfile=<path-to-file>/jgoodies-form-1.5.0.jar \
-DgroupId=jgoodies -DartifactId=forms -Dversion=1.5.0 -Dpackaging=jar
don't forget to do the same with jgoodies-commons.
For you to be able to access the source code and the contextual javadoc you can either
uncompress the jgoodies form zip and make eclipse points to the src folder
generates a jgoodies-form-1.5.0-src.jar by putting the src directory in it and install it in your local repo the same way you did for the jar

Resources