How can I add maven artifact into an existing maven project - maven

How can I add maven artifact into an existing maven project.I understand that I can build a jar locally and use file: protocol but this is possible using maven also.
For example I have a basic maven project
https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project and the artifact:
<repositories>
<repository>
<id>myrepo.org</id>
<name>MyRepository</name>
<url>http://mywork.com/repository</url>
</repository>
</repositories>
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.1.0-RELEASE</version>
I tried adding the code above to the project pom.xml fails because dependency is not in central maven repo.
mvn clean install
I then tried editing my settings.xml by adding the tag, that also failed because dependency was not found.
Im overlooking something pretty basic here.

Maven works on the concept of local and remote repositories.
The local repository refers to a copy on your own installation that is a cache of the remote downloads, and also contains the temporary build artifacts that you have not yet released.
Remote repository is repository you access the artifacts via file or http / ftp protocols , it can be an internal repo or a remote public hosted.
When you add dependency maven search that artifact in local if not found then remote repo will be searched. Still not found then error is reported.
https://maven.apache.org/guides/introduction/introduction-to-repositories.html
In your case, 'ethereumj-core' can not be located neither of location, you need find this jar and do a manual install to local repo.
mvn install:install-file -Dfile=< folder >\ethereumj-core.1.1.0-RELEASE.jar -DgroupId=org.ethereum
-DartifactId=ethereumj-core -Dversion=1.1.0-RELEASE -Dpackaging=jar
once properly installed maven should be able find this artifact when you add this as dependency to any of the projects (in pom.xml).
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.1.0-RELEASE</version>
</dependency>

Related

How to use local maven repository to create container image instead of central maven repository for google cloud

I am trying to create container image of a java application. Dependencies of the application are either on Jfrog repository or my local .m2 folder, not on central.
When I run following command to build and upload image:
gcloud builds submit --tag gcr.io/[PROJECT-ID]/image-name
It tries to download dependencies from central repository which are not available. I have changed the settings.xml of maven to point to Jfrog repository but still it isnt working. I believe it should first check local .m2 repository then it should go to central.
Any explanation/solution will be appreciated. TIA
For Maven to go somewhere else than Maven Central tell it to use a mirror instead. Unfortunately this cannot be done from the command line, but needs to be done with a settings file.
Sample ~/.m2/settings.xml for pointing to a Nexus 3 instance:
<settings>
<mirrors>
<mirror>
<id>nexus1</id>
<mirrorOf>external:*</mirrorOf>
<url>http://nexus/repository/maven-public/</url>
</mirror>
</mirrors>
</settings>
Note that "external:*" says to still use local file repositories if you have artifacts in your source tree you need Maven to resolve locally.
Maven is searching for dependencies only at the central repo.If you want to download dependencies from elsewhere you must specify it to the pom.xml.
<!-- url_of_project -->
<dependency>
....
</dependency>
Local .m2 repo is only searched first for SNAPSHOT versions.If the project is not SNAPSHOT,central repo is searched initially.

How to fix The POM for XXX:jar:1.0 is missing, no dependency information available

We tried to build our project(Spring Boot 2.0.3 with Maven 3.3.9 dependency management)Jenkins Tool(Linux environment).Its saying build failure showing the following message in console "The POM for org.actus:ACTUS-Core-1.0:jar:1.0 is missing, no dependency information available".ACTUS is our custom java library developed by us and its in the local repository also.
This is the first time we started using Jenkins Tool. There are some other modules which depends on this same ACTUS jar.Those are also failing.I have searched for solution on internet.Some people said,make changes to settings.xml file.But in our development machine ,we cant find any such type of settings.xml file(in .m2)
remaining all dependencies are normal spring boot dependencies only.This is the only one external or custom jar.Using mvn install, we kept in maven local repo.
<dependency>
<groupId>org.actus</groupId>
<artifactId>ACTUS-Core-1.0</artifactId>
<version>1.0</version>
</dependency>
I will try to explain as much I can to solve your problem. I hope you are looking for settings.xml to update your maven Nexus repository. If you don't know about nexus repository, it's kind of public repo where you will get all open source dependency.
In your case, from your organization, you should have a private nexus repository and upload ACTUS-Core jar to there.
Then update your settings.xml file to use your company nexus repository. (Please check comments, it will be available in M2_HOME location)
So while you execute mvn install automatically it will upload in your private repository.
Now, in your pom.xml mention the same nexus repository. (It's optional)
Then, in your Jenkins script, you have updated this nexus repo.
So, the key point is you should have your own repo to upload ACTUS-Core jar and need to access the same while you building in Jenkin tool.
OR ELSE
If you find all the above activities in pain / not possible then I can suggest a short cut solution.
Create a lib folder under your project name ( same hierarchy as src) then add your ACTUS-Core.jar and commit that file along with your source code.
Then, update your pom file like below. It will work.
<dependency>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>11.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/fileName.jar</systemPath>
</dependency>

Create local repository for jar

I have main parent POM file which I use to declare all dependencies. I have 3 submaven projects. This is the file structure:
C:\NetBeansProjects\project\pom.xml
C:\NetBeansProjects\project\Core\System_Commons\pom.xml
C:\NetBeansProjects\project\Core\Tracking_Service\pom.xml
I need to use into my project weblogic client - wlfullclient.jar. I create local maven repository:
C:\NetBeansProjects\project\lib\com\weblogic\wlfullclient\10.3.6\wlfullclient-10.3.6.jar
C:\NetBeansProjects\project\lib\com\weblogic\wlfullclient\10.3.6\wlfullclient-10.3.6.pom
I added local repository:
<repository>
<id>lib</id>
<name>In Project Repo</name>
<url>file://${basedir}/lib</url>
</repository>
Jar dependency:
<dependency>
<groupId>com.weblogic</groupId>
<artifactId>wlfullclient</artifactId>
<version>10.3.6</version>
</dependency>
mvn install:install-file -Dfile=C:\wlfullclient-10.3.6.jar -DgroupId=com.weblogic -DartifactId=wlfullclient -Dversion=10.3.6 -Dpackaging=jar -DgeneratePom=true
But I get this error:
[ERROR] Failed to execute goal on project System_Commons: Could not resolve dependencies for project org.project:System_Commons:bundle:1.0: Could not find artifact weblogic:wlfullclient:jar:10 at specified path C:\NetBeansProjects\project\Core\System_Commons\lib\wlfullclien
t-10.3.6.jar -> [Help 1]
The correct path should be here C:\NetBeansProjects\project\lib\com\weblogic\wlfullclient\10.3.6\wlfullclient-10.3.6.jar
Can you give me some idea how I can fix this?
there is not need to create a new repository (do you have any specific requirement?), you already have one, your local repository. The easiest thing to do is, to install this specific jar to your local repository. Usually that resides in the ~/.m2 folder (Mac/Unix) or C:\Documents and Settings{your-username}.m2 for windows. See here.
So what you need to do is apply the following command :
mvn install:install-file -Dfile=wlfullclient-10.3.6.jar
-DpomFile=wlfullclient-10.3.6.pom
-DgroupId=com.weblogic
-DartifactId=wlfullclient
-Dversion=10.3.6
-Dpackaging=jar
In case though you want to have a separate 'local' lib repository you can use the following param on the example above :
-DlocalRepositoryPath=path-to-specific-local-repo
See references here.
You can now reference your jar from your pom and and check of course your local report that the jar is indeed installed and the naming is correct.
Hope that helps.

install JAR from remote repo (clojar)

I want to download and install this Clojure library but cannot for the life of me figure it out. I researched Maven, but couldn't get it to find the repo. How can I easily install a Clojure library onto my machine?
You could add the repository containing this jar to your pom or settings file and specify the relevant jar as a dependency.
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
...
<dependency>
<groupId>clj-http</groupId>
<artifactId>clj-http</artifactId>
<version>0.4.1</version>
</dependency>
download https://clojars.org/repo/clj-http/clj-http/0.4.1/clj-http-0.4.1.jar
mvn install:install-file -DgroupId=clj-http -DartifactId=clj-http -Dversion=0.4.1 -Dpackaging=jar -Dfile=clj-http-0.4.1.jar
If you are using Leiningen you can just read all about how to connect to repository server on a recent Sonatype blog post from Tim O'Brien.
If you are using Maven you should get a repo server like Nexus and setup the clojure repo as another proxy repository and add it to your public group.
If neither of these approaches is ok with you you can use Raghurams approach or number23_cn. Both of them however are semi optimal and will not scale for teams or many artifacts..

How can i use SVN as Maven Repository

I am working on project which has multiple dependencies. Most of the dependencies are available at our centralized maven repository. My project includes some JARs which only specific to my application and unavailable at our Maven repo. Due to some policy/restriction i cant deploy that jars to our maven repository.
When i install these jars in my local repository(i.e.UserHome/.m2/repository) and compile the code its working fine.
Now i want these dependencies in SVN so that we can build the application package using Continuum.(We cant refer local dependency from Continuum server.)
Just to achieve these i copied the locally installed dependency from .m2/repository and committed it in SVN. Then i declared repository in pom.xml like..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://URL/migration2/APP1/src/main/lib/</url>
<layout>default</layout>
</repository>
</repositories>
Now to use dependency from above repo i added code like...
<dependencies>
<dependency>
<groupId>repo.pu</groupId>
<artifactId>Ptestval</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
When i type mvn verify i am getting the below error..
[ERROR] Failed to execute goal on project APP1: Could not resolve dependencies f
or project fileservices.migration2:APP1:jar:1.0: Failed to collect dependencies
for [repo.pu:Ptestval:jar:1.0 (compile)]: Failed to read artifact descriptor for
repo.pu:Ptestval:jar:1.0: Could not transfer artifact repo.pu:Ptestval:pom:1.0
from/to repo.pu (https://URL/migration2/APP1/src/main/lib/): Access denied to:
https://URL/migration2/APP1/src/main/lib/repo/pu/Ptestv
al/1.0/Ptestval-1.0.pom -> [Help 1]
Could you please someone help me to resolve these issue?
EDIT: I created a repository like ..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://SVNUserName:SVNPassword#SVN_URL/BaseProj/ProjA/src/main/lib</url>
<layout>default</layout>
</repository>
</repositories>
This technique works perfectly at my Personal laptop. Maven downloads the listed dependency from repo.
But when tries to use the same in my project on company network it is not working .. It gives the same error which i was getting before using this approach.
Can anyone help me please? What would be problem? Is it a network issue?
Set up a repository manager like Nexus and don't abuse Subversion for something it was not designed for. This is unfortunately done in Google Code.
You must configure your project to use wagon-scm.
See http://maven.apache.org/wagon/wagon-providers/wagon-scm/usage.html

Resources