Maven create a project without sources - maven

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.

Related

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

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]

C-Project: how can I get the dependent DLL file from Sonatype Nexus repository?

I start the build for c-project with jenkins and then in post process I deploy the dll files in sonatyp-nexus repo. It works fine, but now, how can I get the dependent DLL file from Sonatyp-Nexus repo in my local repo, there are C projects (not Java) tool Visual Studio 2010 and 2012. there a solution/idea (powershel or...)?
I deploy the dll files (C project) in Nexus with this maven goal:
mvn deploy:deploy-file -DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<type-of-packaging> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>
I have created for c project a maven pom.xml, where does nothing...
You have to add a dependency to the pom.xml with the coordinates of your dll.
For any other tool usage you can either use the REST API or even easier just to a wget/curl call to download the file. They are avaiable via straight forward normal HTTP.
You can even just browse your Nexus repositories and groups. E.g. Look at
https://oss.sonatype.org/#view-repositories
to see all the repositories on OSSRH. E.g. the releases repository has a lot of components and you can just browse it:
https://oss.sonatype.org/content/repositories/releases/
And you can download any file (e.g. a random one) including dll files or whatever.
wget https://oss.sonatype.org/service/local/repositories/releases/content/aero/m-click/mcpdf/0.2.1/mcpdf-0.2.1-jar-with-dependencies.jar

Install project artifacts to specific directory not .m2

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"

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