How to point to a local repository in the maven build process. In that case I want to link directory with custom jars with the compilation and packaging.
Tried following "mvn compile -Dmaven.repo.local=E:\Test\lib" but it doesn't use located jars for the compilation.
Is there way to include repository through maven pom.xml in the way we inject dependencies?
Just install the custom jars into your local repository (usually located under C:..User.m2\repository) via maven-install-plugin:
mvn install:install-file -Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-Dsources=src.jar] \
[-Djavadoc=apidocs.jar] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=sources] \
[-DgeneratePom=true] \
[-DcreateChecksum=true]
But i would suggest to install a repository manager (like Archiva, Artifactory, Nexus) and install those artifacts there. So you need to do the manual installation work only once and not on every developing machine.
The best way to configure several repositories is via the settings.xml file and not in the pom.xml file.
Exactly pom.xml is for that purpose to maintain dependencies.. you can get more on here
What do you mean by "Local Repository"?
If you mean a local Nexus / Artifactory you can use the Maven sections in your settings.xml
http://maven.apache.org/guides/mini/guide-mirror-settings.html
If you mean the local repository cache (the .m2 dir) that should just work out-of-the-box.
Related
I would like to know if it is possible to deploy a custom jar file into an existing maven repository. By custom, I mean, my own existing jar from my local machine.
So, I have a project test-project on gitlab (https://gitlab.com/group/test-project), and it is a java application that I build and deploy using gitlab pipelines. In the build stage, I am doing mvn deploy and the package test-project.jar is pushed to a gitlab maven repository (https://gitlab.com/group/test-project/-/packages).
Now, I have a dependency.jar file which is listed as a dependency in my pom.xml. I would like to push that file into the same maven repository as my test-project.jar. There is nothing about that in the documentation here. https://docs.gitlab.com/ee/user/packages/maven_repository
I tried to push it with maven-deploy-plugin in a way described here http://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
I am getting an error Failed to deploy artifacts: Could not find artifact... which is strange because I am trying to push new artifact, of course, it does not exist.
I am not sure if this is an issue with GitLab (I doubt that) or I am doing something wrong, or what I want is just not possible.
Edit
I was able to push the package but the thing is I needed to run deploy:deploy-file from the build, not from my local.
This would be the pipeline configuration
stages:
- build
maven-repo-push:
stage: build
image: maven:3.6.2
variables:
GROUP: "com.example"
ARTIFACT: "myproject"
VERSION: "1.1.1"
REPO_PROJECT_ID: "12345678" #gitlab project ID
script:
- mvn deploy:deploy-file
-DgroupId=$GROUP
-DartifactId=$ARTIFACT
-Dversion=$VERSION
-Dpackaging=jar
-Dfile=$ARTIFACT-$VERSION.jar
-DgeneratePom=false
-DpomFile=$ARTIFACT-$VERSION.pom
-Dfiles=$ARTIFACT-$VERSION-tests.zip
-Dtypes=zip
-Dclassifiers=tests
-DrepositoryId=gitlab-maven
-Durl=https://gitlab.com/api/v4/projects/$REPO_PROJECT_ID/packages/maven
-s settings.xml
when: manual
Make sure you have pushed with this configuration the files you want to push in format $ARTIFACT-$VERSION.jar and
The default settings.xml needed for authentication
https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticating-with-a-ci-job-token
Still, my question remains, is it possible to do this from local
You can publish a library/jar from local file system as well, just have a settings.xml something like
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>PUT-YOUR-PRIVATE-TOKEN-HERE</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
Or if you wan to use a group token or deploy token , make sure you update the property name above , documented here https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticate-with-a-deploy-token-in-maven
And then use this to publish your jar on GitLab's package registry, keep in mind that you can only publish to project api endpoints , but you can use group endpoints to download/install artifacts locally
mvn -s settings.xml deploy:deploy-file \
-Durl=https://gitlab.com/api/v4/projects/<PUT-PROJECT-ID-HERE>/packages/maven \
-DrepositoryId=REPOSITORY-ID # has to match the settings.xml server:id \
-Dfile=your-lib.jar \
-DgroupId=your.group.id \
-DartifactId=artifact-name \
-Dversion=1.0 \
-Dpackaging=jar \
-DgeneratePom=false
I'm trying to compile a project in Anypoint studio, and for some reason it's failing on one dependency -
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
<version>12.1.0.2</version>
</dependency>
Should say, when I run this on my Windows laptop i have absolutely no issues and the jars download fine. Running it on my macbook, i get the following error -
Archive for required library: '/Users/matt/.m2/repository/com/oracle/jdbc/ucp/12.1.0.2/ucp-12.1.0.2.jar' in project 's-wms-hj-api' cannot be read or is not a valid ZIP file s-wms-hj-api
the message i get when i update project dependencies is -
[WARNING] Invalid POM for com.oracle.jdbc:ucp:jar:12.1.0.2, transitive dependencies (if any) will not be available, enable debug logging for more details
Is it something Mac related?
The dependency is not available in public repositories so the jar has to be installed manually in the local Maven repository. The error was likely because it was incorrectly installed.
The warning is the expected result because that method doesn't provide the pom.
I'm not sure why you don't see the warning in Windows. Perhaps a different Maven version or using a repository manager?
I've always dealt with Oracle the following way (I'm running a mac as well, though it really doesn't matter):
Download the .jar file from the internet somewhere. Install the dependency using Maven using these instructions: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Here's an example of the command, assuming you downloaded the jar for ucp version 12.1.0.2, you are currently in that directory, and the file is called ucp-12.1.0.2.jar:
mvn install:install-file \
-Dfile=ucp-12.1.0.2.jar \
-DgroupId=com.oracle.jdbc \
-DartifactId=ucp \
-Dversion=12.1.0.2 \
-Dpackaging=jar
This should install into your default ~/.m2/repository. If you want you can verify this with:
ls -al ~/.m2/repository/com/oracle/jdbc/ucp/12.1.0.2.jar
You should see a pom file in there.
Maven will now be ready to grab this file when you specify them in your pom. Keep in mind that the groupId, artifactId, and version parameters for the mvn install command relate exactly to what you'd put in the pom for those same fields.
I have a simple java application - maven project in my Netbeans IDE.
After I created Maven Web Application and added first project as a dependency Netbeans shows that everything is OK, and I can use all methods as well.
But in runtime I am getting
java.lang.ClassNotFoundException: com.example.dal.factory.PersistenceDaoFactory
Is it possible to make web project depending on simple java application without creating multimodule java EE application?
Yes, but you need to install your first project locally:
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=jar
Setting up NetBeans to use a project as a dependency isn't the same thing as having a Maven artifact you can use in other Maven projects; for Maven, you need to have it in a Maven repo.
I am on proxy network and proxy is preventing maven to connect to central repo
Is there any way to download the maven plugins manually and installing the plugins in local .m2 repo.
Thanks
If you have the jar, you can use :
mvn install:install-file -DgroupId=<your_group_name> \
-DartifactId=<your_artifact_name> \
-Dversion=<version> \
-Dfile=<path_to_your_jar_file> \
-Dpackaging=jar \
-DgeneratePom=true
An example of the same:
mvn install:install-file \
-DgroupId="org.apache.maven.plugins" \
-DartifactId="maven-site-plugin" \
-Dversion="3.7.1" \
-Dfile="D:\Jars\maven-site-plugin-3.7.1.jar" \
-Dpackaging=jar \
-DgeneratePom=true
if you don't have the (plug-in) jar, and it's not a private artefact, you can find the jar and the information in repository website (for example http://mvnrepository.com/ ) or download from your private repository like Nexus or Azure Feeds.
Have a look here if you want to configure a proxy for maven. That way you do not need to download the dependencies in any obscure and unreliable way: Howto configure a proxy for Maven
The simplest way to do this is to use any machine that can connect to central to download all repo you need then copy ./m2 manually to your machine with usage of offline flag every build
if your solution is scalable you will need to install nexus or any maven repository on machine can goes outside and you configure maven to see repo machine. and this is the model solution to that case
To install a jar you can use install:install-file to install any kind of jar. But a maven plugin comes with dependencies so you will have to install them. My suggestion would be to copy a .m2 repo from a machine with access to the internet (for maven).
I'm new to Maven and trying to work out how to deal with a situation where I have a set of binary libraries (.jars) that I want to include in multiple Maven-managed projects.
The libraries don't have a pom.xml file and aren't available in any Maven repository.
How should I set up Maven / m2eclipse to include these libraries in my other projects? I'm assuming I need to set up some kine of Maven "wrapper project" to deal with these?
If you're team programming use #limc post.
If it's just for you, there are a couple of ways of dealing with it:
There's a maven plugin to add the jar to your local repository.
mvn install:install-file -DgroupId=<your_group_name> \
-DartifactId=<your_artifact_name> \
-Dversion=<snapshot> \
-Dfile=<path_to_your_jar_file> \
-Dpackaging=jar \
-DgeneratePom=true
Or you can reference the jar file as a system dependency like so:
<dependency>
<groupId>com.package</groupId>
<artifactId>id</artifactId>
<version>5.2</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/my.jar</systemPath>
</dependency>
You will need to first install the jars into your Maven repo shown by #Will's post. Keep in mind, these jars only exist in your Maven repo. In another word, if you are sharing this project code with fellow developers, they have to do the same thing on their own local repos, or else they won't be able to find the jars.
A more elegant solution to team development like this is to host Nexus in some local server. What Nexus does is it groups all the external repositories into one spot (think of it as a proxy). So, you will want to install that jars in Nexus under "hosted repository" (there are 3 types of repo in Nexus, by the way). Then, configure all your team member's development to pull from Nexus instead of the internet. This way, when your team member checks out your project into their local workspaces, everything will be seamless and they will get the jars automatically too. You don't need to configure external repositories in your pom.xml this way. :)