I'm trying to do a mvn install with my local jar.
Here is the pom file, Allure cli.
I want to use the allure-report-builder jar from my local machine, rather than from the maven repo. So I tried this:
mvn install:install-file -Dfile=allure-report-builder.jar -DgroupId=ru.yandex.qatools.allure -DartifactId=allure-report-builder -Dversion=2.1 -Dpackaging=jar install
Here allure-report-builder.jar is my local jar, in the current directory. But it doesn't seems to be working properly. The resulting jar is still using the jar from maven repo.
Where I'm making mistake?
You're trying to do two different things at once:
install:install-file -Dfile=allure-report-builder.jar -DgroupId=ru.yandex.qatools.allure -DartifactId=allure-report-builder -Dversion=2.1 -Dpackaging=jar
and
install
The first one is called a standalone goal. This will just install the file.
The second is called a phase, in this case the install phase. This will run every project-task/goal up until the install, which includes testing and compiling.
Depending on what you want, the first will always work. The second suggest that you have code to compile, but that you don't have all the required dependencies yet. If this is all fixed, you just run mvn install to get this jar in your local repository.
Related
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)
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.
I'm trying to get maven to download all dependencies (compile, test, plugins, etc.) so that I can avoid having our dockerized builds waste unnecessary time downloading them over and over again.
We have dockerized our maven build so that we can run it from our jenkins without having a lot of build specific dependencies installed on the jenkins machine (Java, redis, maven dependencies, etc.). Our build relies on incremental docker builds that only executes steps that actually need re-running.
Our main build is a DockerFile that has several steps to install the jdk, maven, etc. Then it does a
COPY ./pom.xml /opt/inbot-api/pom.xml
RUN mvn dependency:copy-dependencies clean
This will download dependencies to the local maven repository and then cleans out the target directory.
Then we copy the source tree to the image and run the full build.
COPY ./src /opt/inbot-api/src
RUN mvn -e clean install
The general idea is that on a clean machine, docker will execute all the RUN steps but on incremental builds it will only rerun things that need re-running. After each run step, it stores an intermediary image. So, if the pom file doesn't change, there's no need to rerun the dependency fetching step because it would produce the exact same outcome. So, instead it loads the cached intermediary image with all the dependencies already downloaded. This is exactly what we want.
There's a lot more to our DockerFile that is not so relevant here but ultimately it produces a docker file with our compiled artifacts, an nginx config and all our runtime dependencies that we can deploy to ECS.
This nearly works except the mvn clean install still downloads additional plugin dependencies on every build. So, these are dependencies that the copy-dependencies step does not cover.
My question, how do I get RUN mvn dependency:copy-dependencies clean to download all dependencies including the plugin dependencies. I've seen people actually do a mvn verify clean instead of mvn dependency:copy-dependencies clean but that is kind of slow in our case. I was wondering if there was a better way to do this.
I'd appreciate any feedback on how to improve this.
Update
I now do a
RUN mvn -B -T 4 dependency:copy-dependencies dependency:resolve-plugins dependency:go-offline clean
And it still downloads more stuff with the mvn clean install after that. A mvn -o clean install still fails, despite the dependency:go-offline. So, it seems this plugin is broken.
This works for me, no other dependencies to download:
RUN mvn -B dependency:resolve dependency:resolve-plugins
For the plugin i would suggest to use mvn dependency:resolve-plugins
See the documentation: https://maven.apache.org/plugins/maven-dependency-plugin/
I almost resolve with this:
RUN mvn install -DskipTests dependency:resolve dependency:resolve-plugins
This question already has answers here:
How do I add third-party jars into local Maven repository? [duplicate]
(2 answers)
Closed 7 years ago.
I have a group of aboout 20+ third party jars that I need to add to the RUNTIME of an Eclipse Maven project written in Java. These jars are not available from mvnrepository.com. How can I accomplish this?
I tried Build Path.. Configure Build Path and added the jars manually, but this does not make the jar APIs available in Spring MVC controllers because the jars were added to the Build Path and not to the RUNTIME.
I then tried Project Properties -> Deployment Assembly -> Add -> Archives from file system as per this other posting. This imported the jars into /WEB-INF/lib, but did not make their APIs available.
I then read these instructions for importing 3rd party jars into a maven project, but the instructions say to use this line of code mvn install:install-file -Dfile=<path-to-file>. As you can see, this code only specifies one jar, when I have over 20 third party jars to add. The maven link also does not specify where or when to type the code.
Do I navigate the terminal to the root directory of the Maven repository and then type that line of code with 20 variations, once for each jar?
And do I repeat this every time I do a Maven update from within Eclipse? Clearly there has to be an easier way.
What is the easiest and most effective way to get Eclipse Maven to add all 20+ jars to the runtime of my project, so that my Spring mvc controllers can call the APIs when I try Run As... Run on server, and so that the jars are also bundled up with any war files that get created by Eclipse Maven?**
Edit
#DaveNewton suggested writing a shell script. How would such a script look?
I tried mv /path/to/all/the/jars/* /path/to/workspace/MyApp/src/main/webapp/WEB-INF/lib/ and then typed F5 to make the jars visible in the /WEB-INF/lib folder, but this did not resolve the compilation errors from the code elsewhere in the project that calls the API, even after Project... Clean.
Also, I would like for the Eclipse Maven plugin to be able to manage this as much as possible.
Edit 2
As per #alainlompo's suggestion, I imagine a script that includes the following commands, and then the dependency addition below it. Here is what might be in the script:
mvn install:install-file -Dfile=/thefirst.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
mvn install:install-file -Dfile=/thesecond.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
mvn install:install-file -Dfile=/thethird.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
mvn install:install-file -Dfile=/thefourth.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
mvn install:install-file -Dfile=/thefifth.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
mvn install:install-file -Dfile=/thesixth.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
mvn install:install-file -Dfile=/theseventh.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar
And so on for all 20+ jars.
Here is what the dependency tag in the pom.xml might be:
<dependency>
<groupId>my.group.id</groupId>
<artifactId>myartifactid</artifactId>
<version>what goes here?</version>
</dependency>
I would guess I would add some symbols to the groupid to make sure that Maven cannot find anything with the same name at mvnrepository.com. This way the Eclipse Maven update could be used. But what do I use for the version number? Many of the jars have different version numbers.
Also note I am using linux. What would the actual shell script and dependency tag look like?
I think the simplest way to solve this issue is to add your jars to your maven local repository. There is answer for this on SO here and also here. The jars will then be available in Eclipse but also outside eclipse for any of your project that is using maven as a build tool and where the jar is correctly referenced (with the groupId, artifactId and version dependency informations properly provided) as in the following example:
<dependencies>
....
<dependency>
<groupId>org.matlabcontrol</groupId>
<artifactId>matlabcontrol</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
And then you may easily write a .bat or a .sh (depending on the OS) that will do this operation once and for all.
[EDIT]
#CodeMed regarding the jars that are behind the link that you've shared in your comments, some of them are related to each others and therefore will share the same version as the same groupId and most certainly different artifactIds
Example:
org.eclipse.emf.common_2.5.0.v200906151043.jar
org.eclipse.emf.ecore.xmi_2.5.0.v200906151043.jar
Obviously the suffixed 4 parts number is the version number of the jar. So You already have the version number and since it is common to many jar it is to your advantage to define a variable for it in your .bat file and a property for it in your pom.xml file.
Also the groupId will generaly be the same for all related jars. Therefore you could suspect that the groupId would be org.eclipse.emf, and if you google this: maven dependency for org.eclipse.emf + 2.5.0.v200906151043you would find among other links a link to a pom.xml file on a related github project with the following depency informations
I would now be logical to suspect that the artifactId is what's left from the name of the jar commonin one case and ecore.xmiin the other case. This will be checked against a little googling or on Mvnrepository (for example here where we see that this artifact id is also prefixed by the group id)
Therefore we would write the following kind of instructions in a .bat file to install these jars in our local repository
First define a variable to hold the version number
set eclipseEmfVersion=2.5.0.v200906151043
call mvn install:install-file -Dfile=org.eclipse.emf.ecore.xmi_2.5.0.v200906151043.jar -DgroupId=org.eclipse.emf -DartifactId=org.eclipse.emf.ecore.xmi -Dversion=%eclipseEmfVersion% -Dpackaging=jar
call mvn install:install-file -Dfile=org.eclipse.emf.common_2.5.0.v200906151043.jar -DgroupId=org.eclipse.emf -DartifactId=common -Dversion=%eclipseEmfVersion% -Dpackaging=jar
In the case of the second jar however I find on MvnRepository that the artifactId does not set the groupId as its prefix (see here)
Note also that in a .bat file you need to use call mvn (instead of simply mvn as you would do had you only one instruction to run) to be able to execute many maven instruction sequentially.
On the same pattern you can distinguish another group of related jars with the groupId: org.openhealthtools.mdht.uml.cdaand version number 1.2.0.201405161834. You can apply the same approach to install them in your local repository
Here is the successfull test I run (from a bat file that I created in the same directory where I unzip your file) using the first four jars in your list of jars
call mvn install:install-file -Dfile=net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar -DgroupId=net.sourceforge.lpg -DartifactId=net.sourceforge.lpg.lpgjavaruntime -Dversion=1.1.0.v200803061910 -Dpackaging=jar
call mvn install:install-file - Dfile=org.apache.commons.lang_2.3.0.v201005080501.jar - DgroupId=org.apache.commons -DartifactId=lang -Dversion=2.3.0.v201005080501 - Dpackaging=jar
call mvn install:install-file - Dfile=org.eclipse.core.runtime_3.8.0.v20120521-2346.jar - DgroupId=org.eclipse.birt.runtime -DartifactId=org.eclipse.core.runtime - Dversion=3.8.0.v20120521-2346 -Dpackaging=jar
set cdaversion=1.2.0.201405161834
call mvn install:install-file - Dfile=org.openhealthtools.mdht.uml.cda.ihe_1.2.0.201405161834.jar - DgroupId=org.openhealthtools.mdht.uml.cda -DartifactId=ihe - Dversion=%cdaversion% -Dpackaging=jar
You can easily complete the .bat and after running you may manually check the successfull installation of all the jars in your maven local repository.
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