Create local repository for jar - maven

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.

Related

How to convert jars to a maven respository

I am developing an application with JavaPos inclusive. The problem I have is that I am using maven but the hardware manufacturer's libs are all in jars and xml file. How do I bundle them as a maven dependency and use them in my maven project.
Any good idea is welcome so long as it helps me get this done quickly. Help really needed.
Add external jars to local .m2 (for local development)
This approach is not distributable. It assumes just putting jars to local .m2 and nothing more.
For adding jars to local maven repository:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version>
<path-to-file> - is path to jar
Create a new maven repo and distribute it within a project
This approach assumes creating a new maven repository, which will include only external jars. Then this repository placed to the project root, added to git and referented by the project pom.
So anyone, who will download the project will have all maven dependencies in place without extra actions.
Adding jar to the new maven repo:
mvn deploy:deploy-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=jar -Durl=file:./.m2/repository/ -DrepositoryId=project-internal -DupdateReleaseInfo=true
Then reference the repo in your pom:
<repositories>
...
<repository>
<id>project-internal</id>
<url>file:///${project.basedir}/.m2/repository</url>
</repository>
</repositories>
Reference
https://www.google.com/amp/s/roufid.com/3-ways-to-add-local-jar-to-maven-project/amp/

How can I add maven artifact into an existing maven project

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>

Dependency on a local maven project?

Is it possible to have a dependency on a project that is only on my local machine and not in any repository?
If so, how do I specify it in my POM, would I use the following format below?
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency>
Install that dependency to your local maven repository using mvn install. Then your local projects can use it as a dependency. Of course that will only work on that one machine.
If you use Eclipse/NetBeans/IntelliJ and have the dependency as well as the project using that dependency opened, you don't need to install it as those IDEs resolve this without involving the local maven repo.
If your dependency is not a maven project, you simply have to reference the jar file. Or you assign artifactId and groupId and install the jar file to your repo.
Both ways are shown here.
install the dependency using mvn install like take a example of oracle ojdbc6 or ojdbc14 jar we cannot find this jar in central or remode repository so to use this we need to install this jar in maven local repository
Syntax:-
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
example:-
mvn install:install-file -Dfile=C:/oraclexe/app/oracle/product/11.2.0/server/jdbc/lib/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
note:- Cmd should be opened in location of jar only i.e- mvn install:install-file command must run at jar location only
Configuring POM.XML(in program)
<!-- ORACLE database driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
note:-
even one project developed in maven can be added as jar in another

Installed Jar is not picked up in compilation

I successfully installed a local jar to my repo using this command
mvn install:install-file -Dfile=myjar.jar -DgroupId=com.mygroup -DartifactId=art -Dversion=1.3 -DlocalRepositoryPath=/home/me/.m2/repository -Dpackaging=jar
This then created the jar file and pom in my repo correctly, so I can find it under com/mygroup/artifact/1.3/
but when I try to reference it in my project pom using (exactly what is defined in the installed pom)
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>artifact</artifactId>
<version>1.3</version>
</dependency>
I get errors when trying to compile. It fails to find the installed jar.
Failed to execute goal on project myproject: Could not resolve dependencies for project com.myproject:war:1.0: Failure to find com.mygroup:artifact:jar:1.3 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
Im struggling to understand why it is failing to pick up my installed jar. What am I doing wrong?
In your mvn install:install-file you are publishing an artifactID of "art", and later you talk about it being "artifact". I assume this is just a typo in the obfuscation you made after running into the error.
It's hard to see what's going on without more details. I would suggest you blow away your local repo, redeploy the local file, and try again. Also, don't specify a localRepositoryPath (the default is what you want and this is one more potential source of error). Make sure you do this as the same user, preferably from the same shell to be sure.
I used the below ...
mvn install:install-file -Dfile=C:\Autus1\Autus1_Practice\bundle\target\Autus1_Service-1.0-SNAPSHOT.jar -DgroupId=com.autus1.cq5 -DartifactId=Autus1_Service -Dversion=1.3 -DlocalRepositoryPath=C:\Users\manish_ranjan\.m2\repository -Dpackaging=jar
instead of....
mvn install:install-file -Dfile=C:\Autus1\Autus1_Practice\bundle\target\Autus1_Service-1.0-SNAPSHOT.jar -DgroupId=com.autus1.cq5 -DartifactId=Autus1_Service -Dversion=1.0-SNAPSHOT -DlocalRepositoryPath=C:\Users\manish_ranjan\.m2\repository -Dpackaging=jar
and it worked. :)
The only change was version "1.3" instead of "1.0-SNAPSHOT" which gave me the solution and my project2 started recognizing this dependency from my project1
<dependency>
<groupId>com.autus1.cq5</groupId>
<artifactId>Autus1_Service</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
Thanks for the clue!

Downloading jar from github repo fails while using maven compile

I am new to Maven. Using the instructions mentioned here: http://activeintelligence.org/blog/archive/hosting-maven-repository-for-third-party-jars-on-git-bitbucketgithub/, I created a github maven repo for third-party jar. I can see the jar (and the corresponding pom) here: https://github.com/sushilmittal/wiki-keyword-extraction/tree/master/repository/com/rapid_i/rapidminer/5.3.006
My pom.xml has these two entries corresponding to the above jar:
<dependency>
<groupId>com.rapid_i</groupId>
<artifactId>rapidminer</artifactId>
<version>5.3.006</version>
</dependency>
and
<repositories>
<repository>
<id>wiki-keyword-extraction</id>
<url>https://github.com/sushilmittal/wiki-keyword-extraction/tree/master/repository/</url>
</repository>
</repositories>
When I do mvn compile, I get the following warning:
Downloading: https://github.com/sushilmittal/wiki-keywordextraction/tree/master/repository/com/rapid_i/rapidminer/5.3.006/rapidminer-5.3.006.pom
[WARNING] Checksum validation failed, expected https://github.com/sushilmittal/wiki-keyword-extraction/tree/master/repository/com/rapid_i/rapidminer/5.3.006/rapidminer-5.
3.006.pom
which further leads to the following error:
[ERROR] Failed to execute goal on project DataIndex: Could not resolve dependencies for project DataIndex:DataIndex:jar:0.0.1-SNAPSHOT: Could not find artifact com.rapid_i:rapidminer:jar:5.3.006 in wiki-keyword-extraction (https://github.com/sushilmittal/wiki-keyword-extraction/master/repository/) -> [Help 1]
If I manually go to the location https://github.com/sushilmittal/wiki-keywordextraction/tree/master/repository/com/rapid_i/rapidminer/5.3.006/, I can see the files. So I fail to understand why maven is unable to download the jar/pom from that location.
Any ideas?
First off, please read this post
Second, using a source control system as a Maven Repository is a really bad plan. The recommended thing to do is use a Maven Repository Manager. There are at least three implementations available and there is even an on-line hosting service.
Thirdly, if you insist on following this misguided plan, you need to tell Maven the https path to the raw files in the GitHub repo, not the HTML rendering of the file content with line numbers etc

Resources