maven deploying 3rd pom's without jar to nexus repository - java

When I want to deploy 3rd jars to my nexus 3 repository I use this command:
mvn deploy:deploy-file
-Dfile=<path-to-jar>
-DpomFile=<path-to-pom>
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml>
-Durl=<url-of-the-repository-to-deploy>
but this command works only on jars with pom, and there is many artifacts that have only pom without jar, so i am looking for a way to deploy only pom without a jar file. My maven version is 3.3.9

mvn deploy:deploy-file
-DgroupId=com.xxx.xxx.xxxx
-DartifactId=xxxxx
-Dversion=x.x.x
-DgeneratePom=false
-DrepositoryId=nexus
-Dpackaging=pom
-Dfile=D:/xxx/xxxxx-x.x.x.pom
-DpomFile=D:/xxx/xxxxx-x.x.x.pom
-Durl=http://xxx.xx.xx.xx:8081/repository/thirdparty
-Dfile, is mandatory for Maven deploy-file. Therefore you have to specify a file.
In this case, you can point the same pom file for both -DpomFile and -Dfile.
This works in Nexus OSS version 3.23.0-03 with Maven 3.5.2

Related

Maven cannot find JAR

Recently I tried to develop an interface for my group. My service runs and works well on my local machine, but when trying to use Maven Compile in IDEA, the compilation fails and tells me it cannot find my JAR package. The JAR package I use is JAVE (Java Audio Video Encoder), which was manually added into my CLASSPATH. I know Maven cannot find JAR package without adding dependency to pom, but I can't find the Maven dependency for JAVE, it seems that they only provide a JAR package for users. JAVE HomePage
So in this case, what should I do if I want to successfully compile my code using Maven? I need to deploy my service in the future, so manually adding JAR package to my CLASSPATH instead of adding dependency to pom is definitely not acceptable.
You can install a maven jar locally using:
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
You can install the artefact to either your local or a remote maven repo or you could use it as a system-scoped dependency (see https://stackoverflow.com/a/2177417/9705485 or http://roufid.com/3-ways-to-add-local-jar-to-maven-project/ for examples)

How to deploy tools.jar into Nexus using Maven?

From the same directory I tried to deploy
spark-assembly-1.6.2.2.5.0.0-1245-hadoop2.7.3.2.5.0.0-1245.jar
and
tools.jar
(the later being a dependency of the first)
Despite launching the same commands:
mvn deploy:deploy-file -Dfile=./spark-assembly-1.6.2.2.5.0.0-1245-hadoop2.7.3.2.5.0.0-1245.jar -DgroupId="spark.yarn.jar" -DartifactId="spark-assembly-1.6.2.2.5.0.0-1245-hadoop2.7.3.2.5.0.0" -Dversion="1245-SNAPSHOT" -Dpackaging="jar" -DrepositoryId="stmms-id" -Durl="http://nexus.some.dns.com:8090/repository/maven-snapshots"
mvn deploy:deploy-file -Dfile=./tools.jar -DgroupId="jdk.tools" -DartifactId="jdk.tools" -Dversion="1.7.0_07" -Dpackaging="jar" -DrepositoryId="stmms-id" -Durl="http://nexus.some.dns.com:8090/repository/maven-snapshots"
the first is successfull but the second fails:
I also tried maven-deploy-plugin but with no much success.
Your repository maven-snapshots is a SNAPSHOT repository. You can only deploy SNAPSHOT versions to it.
So -Dversion="1245-SNAPSHOT" is ok, but -Dversion="1.7.0_07" is not.

Using third party lib with maven

I'm trying to use Synthetica library with maven but I failed.
There are 2 different jar file I need to import. First one is synthetica.jar and the other one is syntheticablackeye.jar.
I tried mvn install:install-file but it didn't solve the problem.
I can use them with eclipse but currently I do not use any IDE like eclipse also I'm on linux.
Steps I have done:
(This is for synthetica.jar)
mvn install:install-file -Dfile=~/Dropbox/github/ChatAppServer/synthetica.jar -DgroupId=de.javasoft.plaf -DartifactId=synthetica -Dversion=1.0.0 -Dpackaging=jar
(This is for syntheticaBlackEye.jar)
mvn install:install-file -Dfile=~/Dropbox/github/ChatAppServer/syntheticaBlackEye.jar -DgroupId=de.javasoft.plaf -DartifactId=synthetica -Dversion=1.0.0 -Dpackaging=jar
the problem is how should I add dependency when the to jar files file structers are same?
I did these and It worked fine but when I check local mvn repos in my pc(.m2/repo/) there were no jar files. synthetica and syntheticablackeye file structers are same is this a problem? If it is what can I do?
What am I missing?
Edit: When I change artifactId and groupId maven trying to download jar files but they are in local repo?
You have not supplied any details about any errors you are getting or what command you used exactly to install the JARs, so it is hard to know what exactly is not working.
You can install 3rd party JAR files in your local Maven repository with a command like this (see also Maven's Guide to installing 3rd party JARs):
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
For example:
mvn install:install-file -Dfile=synthetica.jar -DgroupId=com.synthetica
-DartifactId=synthetica -Dversion=1.0 -Dpackaging=jar
Then you refer to it in the pom.xml of your project with the same Maven coordinates:
<dependency>
<groupId>com.synthetica</groupId>
<artifactId>synthetica</artifactId>
<version>1.0</version>
</dependency>
edit - Do not use the same groupId, artifactId and version for both JAR files, otherwise Maven cannot tell them apart.

Add artifact to local repository from project

Is there a way add artifact to local maven repository from my eclipse project?
currently i have a project that contain many jars, and i have started using maven. what i need is to add all these jars to the local repository in an automated way without redownload them or adding them one by one and specifying their coordinates.
Make a new Maven project in Eclipse, and add all your code to the src/main directory. Now you will have lots of compile errors, because of missing dependencies.
Now start auto adding the dependencies. In Intellj you can add something using alt-enter, which also has the option to "add maven dependency". This adds that dependency from the maven repository to the pom. I do not know eclipse well enough, but it probably also has this feature.
Now, in a normal project, you will find most of your required dependencies somewhere in Maven Central. If you miss any, you can add them using manual installation to your local repository, as suggested by Manas Mukherjee
mvn install:install-file -Dfile={jar_file_name_path}.jar -DgroupId={groupId}
-DartifactId={artifactId} -Dversion={version} -Dpackaging=jar
you can write a script using mvn install command.
mvn install:install-file -Dfile={jar_file_name_path}.jar -DgroupId={groupId}
-DartifactId={artifactId} -Dversion={version} -Dpackaging=jar
You can add all dependencies in pom file as well
Thanks

Maven: How to include jars in Eclipse, which are not available in repository?

I have copied the JARs into src\main\webapp\WEB-INF\lib.
I use eclipse. If I add the jars one-by-one to Project-> Java Build Path-> Add jars, then I do Project-> Maven-> Update Project Configuration, they are removed by Maven. And Eclipse shows errors, which contain " xxx cannot be resolved".
Env:
Eclipse Java EE IDE for Web Developers.
Version: Indigo Service Release 1
Build id: 20110916-0149
m2e - Maven Integration for Eclipse 1.0.100.20110804-1717
Note: I don't want to create my own Maven repository. It will be just used once.
How should I proceed ?
Not all libraries can be found in a public Maven repository, for example your own libraries or proprietary libraries. Anyway first you can search the Maven Repository, maybe some of them are there.
In case they are really not there, and you don't want to install Nexus or Artifactory, you can choose one of these two approaches:
install the jars in your local repository cache, no need to create a special repository. See the instructions on mkyong.
another approach is using system dependencies, you just put a path to reach the Jar in the filesystem. It's a less recommended approach, but if you really want it will work. Here is the official documentation.
Add this an a Systems Dependency.
In case you want to add this (this uses jquantlib as example) to the maven local repo use:
mvn install:install-file -Dfile=./jquantlib-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib -Dversion=0.2.4 -Dpackaging=jar
In order to do this I use a batch file
#echo off
cd lib
CMD /C "mvn install:install-file -Dfile=./jquantlib-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-helpers-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-helpers -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-samples-0.2.4-ubber.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-ubber -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-samples-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-samples -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./ta-lib-0.4.0.jar -DgroupId=com.tictactec -DartifactId=ta-lib -Dversion=0.4.0 -Dpackaging=jar"
You can use a similar script file on other systems.
I believe the system dependency approach shouldn't be used unless you don't have any other choice, and that's because you're loosing the whole 'build portability thing' here.
Of course you can store your jars in your source control system together with your project's source files, but I don't think its a good approach neither...
Using only install:install-file is not good enough - this would indeed deploy the jars in the proper format into your local repository, but what happens when you'll move to another computer and start to build your project there?
You will need to make this once more.
So, If you don't want to install nexus/artifactory (which is the best solution, I believe), you probably should create an another repository (just in a file system on some of your servers), and deploy the jars there (you can use mvn install:install-file as was suggested here, and then just copy the whole tree). Now you can configure apache web server and access the directory with all your jars via http. I don't believe its better then nexus/artifactory approach, but it can be a little be easier to do if you're familiar with apache web server.
In order to get your maven aware about this new repository you'll need to edit the %MAVEN_HOME%\conf\settings.xml file
There are atleast three approaches in which 3rd party JARs can be added to Maven projects.
Install manually using mvn install command
Adding the location of jar file in pom dependency with the the following tag system
Creating a 'dummy' maven repository pointing to jar location.
While approach 1 and 2 has been suggested above, I will focus on third approach which I find more cleaner and does not require any mvn command and works out of box from any IDE.
Step 1: Add the location of local 'dummy' repository in pom.xml
<repositories>
<repository>
<id>repo</id>
<name>repo</name>
<url>file:${project.basedir}/src/main/resources/lib</url>
</repository>
</repositories>
Here the 'dummy' repository location is the 'lib' folder of my project directory
Step 2 : Add the jar dependency into your pom.xml
<dependency>
<groupId>com.cloudera.impala</groupId>
<artifactId>impala-frontend</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
choose any groupId but make sure that artifactId and version is of the format <artifactId>-<version>.jar ( Name of 3rd party jar)
Step 3 : Create the folder structure as per the groupId,artifactId and version mentioned in the Step 2 in your local 'dummy' repository. So in this case the folder struction would be /src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/
Place your jar in the version folder and build your project.
You will get the following output which treats your 'dummy' repository to be the provider of your 3rd party jar.
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.pom
[WARNING] The POM for com.cloudera.impala:impala-frontend:jar:0.1-SNAPSHOT is missing, no dependency information available
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[WARNING] Could not validate integrity of download from file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar: Checksum validation failed, no checksums available
[WARNING] Checksum validation failed, no checksums available from repo for file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[INFO] Downloaded from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar (7.0 MB at 79 MB/s)
[INFO]
To add external JAR files not in the local repository simply right click on your main source folder and from the build path menu select: "configure build path", then navigate to the libraries tab and click "add external JAR files". next, locate the JAR (or zip) file you would like to add as a library and click ok.
Congratulations, you have now successfully added an external JAR (or zip) to your build path and you can now import any classes from that JAR file in your project without throwing an errorPicture How-To :) http://hostthenpost.org/uploads/541be8420657320c74489ff8d456ad08.png

Categories