Use WAR as dependency in Maven - 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]

Related

How to directly upload a jar file to nexus repository using maven without pom file or settings.xml file?

Context : I do not have UI access to Nexus Repository but I have access to Jenkins configured with access to nexus repository. I have a shaded jar in my git repository which needs to be directly uploaded to nexus repository using maven without pom.xml or settings.xml file.
Problem : How to upload a jar in git repo to nexus repository using Jenkins with maven plugin ?
I tried searching for this specific usecase and was not able to find a solution.
You can create a Jenkins Job to clone git repository [Source Code Management] where the required jar is present and configure Jenkins Job Build stage with below maven command [Execute Shell] :
mvn deploy:deploy-file \
-DgroupId=com.example.test \
-DartifactId=test-module \
-Dversion=1.0.0 \
-DgeneratePom=true \
-Dpackaging=jar \
-DrepositoryId=sample-rel \
-Durl=http://nexus.private.net/Your_Nexus_Repository_Path \
-Dfile=./PATH_TO_JAR_FILE
(edit: multi-line for legibility)
The deploy:deploy-file solution above still requires a settings.xml file. The login credentials will be retrieved from the setting.xml "servers" section using the ID specified in the repositoryId parameter. There isn't any way that I know of to deploy using Maven without a settings.xml file. But you can specify a custom settings.xml file with "mvn -s some/path/settings.xml".
Alternatively, you could use a Jenkins plugin to do the deploy: https://help.sonatype.com/integrations/nexus-and-continuous-integration/nexus-platform-plugin-for-jenkins#NexusPlatformPluginforJenkins-RepositoryManager3Integration

project.build.finalName is not working with deploy-file goal

can we use project.build.finalName in the command line options of the mvn deploy:deploy-file goal.
here is my command:
mvn deploy:deploy-file -DgroupId=abc -Dproject.build.finalName=test -DartifactId=test -Dversion=1.0 -Dpackaging=jar -Dfile="file_path" -Durl=url -DrepositoryId=id`
the details are :
first, there is no POM file available.
i am just executing this command to upload the artifact in nexus.
now the issue is , the artifact being uploaded has the name as : ${artifactId}-${version}
and i dont want version in the finalname. i have alrady gone through the couple of posts and found that we can use project.build.finalName
but in this case , it is still uploading with version number. how can i fix that ?
You need to drop the -Dproject.build.finalName part and add -DgeneratePom=true instead, as you're already specifying the full path to the artifact via the -Dfile.
You cannot not have the version part when deploying to a Maven remote repository (which is what you're trying to do). When deploying to a Maven repository, your artifact's GAV (groupId, artifactId, version, type and classifier) coordinates will get translated into:
${groupId}/${artifactId}/${version}/${artifactId}-${version}.jar
For example, for these GAV-s:
groupId : com.foo
artifactId : bar
version : 1.2.3-SNAPSHOT
type : jar
classifier : [null, javadoc, sources]
You will get a path like:
com/foo/bar/1.2.3-SNAPSHOT/bar-1.2.3-SNAPSHOT.jar
com/foo/bar/1.2.3-SNAPSHOT/bar-1.2.3-SNAPSHOT-javadoc.jar
com/foo/bar/1.2.3-SNAPSHOT/bar-1.2.3-SNAPSHOT-sources.jar
The -Dproject.build.finalName is for cases, where you'd like the artifact to have a different name so that, (for example), your build process can use that for simplicity, or convenience.
If you're deploying using deploy-file and have no pom.xml file, your command-line should look something like this:
mvn deploy:deploy-file \
-DgroupId=com.foo \
-DartifactId=bar \
-Dversion=1.2.3-SNAPSHOT \
-Dpackaging=jar \
-Dfile="path\to\foo-1.2.3-SNAPSHOT.jar" \
-Durl=http://the-url-to-your-repository/ \
-DrepositoryId=the-repository-id-defined-in-your-settings.xml-that-has-your-credentials

How can i add a self created jar say jarFile.jar to pom.xml

i have created a jar with name jarFile.jar, as you can see i haven't mentioned any version of the jar which is creating problem while i trying to add this jar to pom.xml without changing the name of the jar
`<dependency>
<groupId>com.my.jar</groupId>
<artifactId>jarFile</artifactId>
<version></version>
</dependency>`
If you don't specify version, maven can't know which jar to take.
Specify the version of the jar you installed.
The procedure to install a jar i use is:
mvn install:install-file -DgroupId=com.example -DartifactId=awesomeJar -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true -Dfile=C:\myJar.jar
(for external jars)
or
mvn clean install -o
from the project folder for installing my own dependency jars.
I don't see the real question here.

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.

Resources