How to put own jar to project(non local) repository? [duplicate] - java

This question already has answers here:
how to deploy my artifact on to my nexus?
(4 answers)
Closed 8 years ago.
I have a jar file with source code. Our project has own Nexus repository. I want load this file to into this repository and get dependency tag for download it.
Can you describe the procedure ?
I want to write line in cmd

You have to add a dependencies tag in your pom.xml :
<dependencies>
<dependency>
<groupId>org.yourgroupid</groupId>
<artifactId>your-artifact-id</artifactId>
<version>your-version</version>
</dependency>
</dependencies>
And you have to add a repositories tag on which you will put your repository URL:
<repositories>
<repository>
<id>your-id</id>
<url>http://your-url</url>
</repository>
</repositories
Edit
Here is the way to deploy to your Nexus:
<distributionManagement>
<repository>
<id>nexus-repo</id>
<url>http://your-nexus</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://your-nexus</url>
</snapshotRepository>
</distributionManagement>
It can use scp or you may need to add wagon-plugin or cargo-plugin.
See more: http://maven.apache.org/pom.html#Distribution_Management

Related

Adding external jar to maven repository not working [duplicate]

This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 2 years ago.
I've installed my jar in my local repo as said in maven docs :
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<dans>
-DartifactId=<dans-lib>
-Dversion=<1.0.0>
-Dpackaging=<jar>
-DgeneratePom=true
I can see in my /home/.m2/repository that the location is created and in the dans/dans-lib/1.0.0 there is my jar file.
Unfortunately when I'm trying to add maven dependency in my pom.xml
<dependency>
<groupId>dans</groupId
<artifactId>dans-lib</artifactId>
<version>1.0.0</version>
</dependency>
I got error Dependency dans:dans-lib not found. I've got no idea what might be the problem
First solution is to add local repo to pom.xml something like this
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.basedir}/local-maven-repo</url>
</repository>
</repositories>
2nd solution woudld be to load jar file
<dependency>
<groupId>dans</groupId
<artifactId>dans-lib</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>

Change a content a maven dependencies

I'm currently changing a docker image. The docker image creates a server that allows running some experiments. To adapt its functionality for my purpose, I have to change a class that is contained in a dependency jar file. In the pom.xml file, such jar dependency is downloaded with its dependencies from a nexus repository. I presume that a possible solution is to create a repository in the nexus repository (localhost) and then upload the jar file with its dependencies, right? Anyway, I would have no idea how I can do it. Below is the code concerning it.
Could someone help me up, please?
<repositories>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.liveontologies</groupId>
<artifactId>pinpointing-experiments</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Yeah you're on the right track. What you're asking about is called a "deploy" in maven. So to deploy your jar generally you'll need to:
Create your nexus instance
Add your new repository to your pom file
Add the maven-deploy-plugin to your pom
Make your code changes
Deploy your jar with the mvn deploy command
Two good resources for lots of details on the steps and the exact content to add to your pom.
https://www.baeldung.com/maven-deploy-nexus
https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html

How Do I Add A Maven Repository Other Than Central?

I am trying to add the "selenium standalone server jar" to my maven project. I found this:
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server-standalone/2.53.0
Copying the dependency is giving me a missing artifact error which probably mean my current maven settings isn't pointing to the repo that has this jar file. The url is http://repo.jenkins-ci.org/releases/org/seleniumhq/selenium/selenium-server-standalone/2.53.0/ How to I update my pom file so that I can add this dependency?
Check maven documentation:
https://maven.apache.org/guides/mini/guide-multiple-repositories.html
<project>
...
<repositories>
<repository>
<id>my-repo1</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
<repository>
<id>my-repo2</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
</repositories>
...
</project>

Maven. Adding maven repository for activiti

The problem is that I'm trying to make somelike the helloworld with Activiti but I have an error here
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.1</version>
</dependency>
the error is the following: 'Description Resource Path Location Type
Missing artifact org.activiti:activiti-engine:jar:5.1 pom.xml /IllMakeThisTestApp line 29 Maven Dependency Problem
Trying to resolve it I've found the following recomendation here: "The download contains all the libraries that you need to work with Activiti. But for developers that prefer to use Maven, add the following reposiory"
<repositories>
<repository>
<id>Alfresco Maven Repository</id>
<url>https://maven.alfresco.com/nexus/content/groups/public/</url>
</repository>
</repositories>
But where shall I place it? To the file called settings.ini placed in M2_HOME/conf? This file is full of comments with no any sign of repositories. So I have no idea how to do this and ask you for help
You should place that in your pom.xml - see the Maven reference on the subject:
<project xmlns="http://maven.apache.org/POM/4.0.0"...
...
<repositories>
<repository>
<id>Alfresco Maven Repository</id>
...
You will only need to tinker with the Maven config if you need to setup a mirror for the repo, eg. in case your organisation has it's own Nexus/other repo mirroring the outside "world".
Cheers,
You can place right under project. For example
<project>
....
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
In default maven will try to download all the artifacts from maven central. You can add any number of added repositories using tag given above. Alfresco is yet another open maven repository.

Loading Maven dependencies from GitHub [duplicate]

This question already has answers here:
Can I use a GitHub project directly in Maven?
(3 answers)
Closed 2 years ago.
How do I add a Java library from its GitHub repo (the library uses Maven as a build system) as a dependency to my Maven project? Can I do that without downloading and compiling the library?
Now you can import a Java library from a GitHub repo using JitPack.
In your pom.xml:
Add repository:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Add dependency
<dependency>
<groupId>com.github.User</groupId>
<artifactId>Repo name</artifactId>
<version>Release tag</version>
</dependency>
It works because JitPack will check out the code and build it. So you'll end up downloading the jar.
If the project doesn't have a GitHub release then its possible to use a commit id as the version.
At the moment there is no way you can do this unless the maintainer of the library provided a way to do this.
So on the title page of the library the should be an instruction containing the repository address like:
<repositories>
<repository>
<id>YOUR-PROJECT-NAME-mvn-repo</id>
<url>https://raw.github.com/YOUR-USERNAME/YOUR-PROJECT-NAME/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
And a dependency name:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
</dependency>
This means that all artifact of your project including your dependency will be searched in this repo.
You could also have a glance at pom.xml to check if there was an effort made to deploy artifacts to a remote repo. Typically the keywords are oss.sonatype.org or raw.github.com like in this case.
FYI, here is a way to provide a repo for your gihub artifact: Hosting a Maven repository on github.
Github now supports packages https://help.github.com/en/github/managing-packages-with-github-packages/configuring-apache-maven-for-use-with-github-packages
You can follow the steps above to deploy Jar files to github properly.
Another very nice thing about Jitpack is, it has a lookup button on the main page. And if you type the URL of your GitHub repository, it displays different commits of the source code, and you can select which commit/tag you want. The Jitpack creates pom dependencies for you.
It became dead simple.

Categories

Resources