Installed Jar is not picked up in compilation - maven

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!

Related

packaging maven project with external jar

I've been trying to make a runnable jar from my project (in Intellij IDEA) which has a dependency to an oracle (driver -> ojdbc6) jar. When I package the project with all of the dependencies, the only one what will be excluded is the jar. Which means my db queries are going to fail when I run it.
I've found several similar questions*, but I've failed the execution of them, because I don't know the groupid and artifact id of the oracle's jar.
*like this one: build maven project with propriatery libraries included
p.s.: the jar wad added through the IDEA's feature (project structure -> modules), and with this solution the project could run without failure. The problem starts with the packaging.
Short Solution: Try using the below:
<dependency>
<groupId>LIB_NAME</groupId>
<artifactId>LIB_NAME</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/YOUR_LIB.jar</systemPath> // give the path where your jar is present
</dependency>
Make sure that the groupId, artifactID and the version number are unique.
Long Solution:
Download the jar file to your machine.
Navigate using the prompt to the folder where you downloaded the jar.
Run the following command to install the jar to your local repository.
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
Finally, add the dependency to the pom.xml.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
Also, don't forget to use -U option while running the project.

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

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.

Oracle JDBC ojdbc6 Jar as a Maven Dependency

I cannot seem to get Maven to bundle the ojdbc6.jar file into my project's war file. I have it working within the POM file when specifying a dependency directly for Hibernate tools. But it won't get bundled with the project's war file, and therefore my project won't run on Tomcat.
I have tried every solution I can find out there on the net, including those specified for this question here:
Find Oracle JDBC driver in Maven repository
Most recently, I did the following:
Download the jar file to my machine
Run the following command to install the jar into my local repository:
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
(I've tried all kinds of variants of that command, too.)
Finally, I put the dependency into my pom file:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
I run a clean build, but it fails:
mvn -U clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jazztwo 0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/com/oracle/ojdbc6/11.2.0.3/ojdbc6-11.2.0.3.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.700s
[INFO] Finished at: Tue Mar 27 15:06:14 PDT 2012
[INFO] Final Memory: 3M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project jazztwo: Could not resolve dependencies for project edu.berkeley:jazztwo:war:0.0.1: Could not find artifact com.oracle:ojdbc6:jar:11.2.0.3 in central (http://repo1.maven.org/maven2) -> [Help 1]
Why doesn't this work? I'm ready to throw expensive computer parts across the room. This has wasted so much time. (Thank you, Oracle. How much did we pay you again?)
Is it because I'm on a Mac, perhaps?
It is better to add new Maven repository (preferably using your own artifactory) to your project instead of installing it to your local repository.
Maven syntax:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
...
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
Grails example:
mavenRepo "https://code.lds.org/nexus/content/groups/main-repo"
build 'com.oracle:ojdbc6:11.2.0.3'
For anyone reading this post in the future, you don't need to cd to the directory where the jar is present. Here is what you need to do -
Go to your project folder from where you can run maven commands (When you do an ls -ltr in this folder, you should see pom.xml)
Do this -
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=<Path where the jar is, example downloads>/ojdbc6.jar -DgeneratePom=true
Once this is done, you can add the dependency in your pom.xml, something like this -
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
The correct answer was supplied by Raghuram in the comments section to my original question.
For whatever reason, pointing "mvn install" to a full path of the physical ojdbc6.jar file didn't work for me. (Or I consistently repeatedly flubbed it up when running the command, but no errors were issued.)
cd-ing into the directory where I keep ojdb6.jar and running the command from there worked the first time.
If Raghuram would like to answer this question, I'll accept his answer instead. Thanks everyone!
mvn install:install-file
-Dfile=C:\Users\xxxx\Downloads\lib\ojdbc6.jar
-DgroupId=com.oracle
-DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
to resolve the ORACLE JAR issue with the Spring Application,
Oracle JDBC ojdbc6 Jar as a Maven Dependency
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>`
First you need to download the particular jar from Oracle site (ojdbc.jar version 11.2.0.3)
if you download it to C:\filefolder
go to that directory in cmd prompt and provide the below command.It will install the dependency.Then you can build your project.
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.4.0 -Dfile=ojdbc6.jar -DgeneratePom=true
After executing
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
check your .m2 repository folder (/com/oracle/ojdbc6/11.2.0.3) to see if ojdbc6.jar exists. If not check your maven repository settings under $M2_HOME/conf/settings.xml
Below config worked for me. Refer this link for more details.
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
Since Oracle is the licensed product, there are issue in adding maven dependency directly. To add any version of the ojdbc.jar, below 2 steps could do.
Run the below command to install ojdbc.jar into local maven repository.
/opt/apache-maven/bin/mvn install:install-file
-Dfile=<path-to-file>/ojdbc7.jar
-DgroupId=com.oracle
-DartifactId=ojdbc7
-Dversion=12.1.0.1.0
-Dpackaging=jar
This will add the dependency into local repository.
Now, add the dependency in the pom file
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1.0</version>
</dependency>
I have tried using the dependency without version tag and its worked fine for me.
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
I followed below command it worked:
mvn install:install-file -Dfile=E:\JAVA\Spring\ojdbc14-10.2.0.4.0.jar\ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar
After installation check that jar is installed correctly on your M2_repo.
Add Following dependency in pom.xml
<dependency>
<groupId>com.oracle</groupId>
<artifactId>oracle</artifactId>
<version>10.2.0.2.0</version>
</dependency>
Go to the C drive->user->PcName->find .m2 and Paste the downloaded ojdbc jar file there, Server will automatically pick this.
Public: https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc6/11.2.0.4
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
For Ubuntu Issue
In ubuntu .m2\ folder is difficult to find and difficult put jar into repository ,So when we put command of Step 1 in Command Prompt, then it create ojdbc7 jar into local repository.
Step 1: Go to any location like /home/user/Documents open terminal and put this command
Command
mvn install:install-file -Dfile=path_of_downloaded_jar/ojdbc7.jar
-DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2.0 -Dpackaging=jar -X
Step 2: Put this dependency in pom.xml
Dependency
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2.0</version>
</dependency>
Step 3: Update maven.
Please note:
You can change versions of ojdbc like ojdbc6/7/8 according your requirement.
Oracle JDBC drivers and other companion Jars are available on Central Maven. We suggest to use the official supported Oracle JDBC versions from 11.2.0.4, 12.2.0.2, 18.3.0.0, 19.3.0.0, 19.6.0.0, and 19.7.0.0. These are available on Central Maven Repository. Refer to Maven Central Guide for more details.
It is recommended to use the latest version. Check out FAQ for JDK compatibility.

Jenkins and maven multi module Projects missing artifacts

This is a simplified example of an ear project, the parent pom aggregates the EAR, the EJBs, and the jars.
I have this structure in a Maven project, stored in SVN:
parent/
|- pom.xml
|- modulA/
| |- pom.xml
|- modulB/
| |- pom.xml
modulB has a Dependency of modulA
The pom.xml have the modules section
<modules>
<module>modulA</module>
<module>modulB</module>
</modules>
And a Dependency Management section
<dependencyManagement>
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>modulA</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>modulB</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
The sub-modules reference the parent
<parent>
<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>0.0.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
in my PC when I compile for the first time with maven 2.2.1 (windows)
mvn clean compile
I don't have any problems
but.... when Jenkins try to compile for first time (Maven 2.2.1 Linux RedHat)
Missing:
----------
1) modulA:jar:0.0.2-SNAPSHOT
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=group -DartifactId=modulA -Dversion=0.0.2- SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=group -DartifactId=modulA -Dversion=0.0.2-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) modulB:ejb:0.0.2-SNAPSHOT
2) modulA:jar:0.0.2-SNAPSHOT
----------
1 required artifacts are missing.
Why????????
After that if I deploy the project from my pc to Artifactory, Jenkins doesn't have problems, because Jenkins downloads the artifact from the repository... but why does Jenkins depend on the artifacts in the repository?
:(
Thanks in Advance
EDIT:
I thought the dependencyManagement section only "defines" the dependencies, but if a submodule doesn't use the dependency, the dependency isn't added to the submodule.
I drop the dependencyManagement section and the problem in Jenkins still occurs.
It works on my PC without problems.
I hope above dependency management section is inside the parent pom. According to your requirement modulB has a Dependency of modulA. So I suggest you to include dependency in moduleB instead of having it in the parent pom. I think when it runs in first time maven is looking for both dependencies since you have mentioned in in the parent pom.Look at your project build order. First it builds module A and then B. In your case I hope you have include all other dependencies in moduleA's pom file and once it built it will deploy a jar file in to m2 repository. And then moduleB start to build and since your dependency is already in the m2 repository it wont shout and project will build successfully.
The first time you build parent project, your Jenkins user's maven repository won't have modulA installed. clean compile is then run successfully in modulA, but nothing is installed. When it is run in modulB, the dependency on modulA can't be resolved.
If your Jenkins job's goal was clean install instead of clean compile, then modulA's artifacts would be installed to the Jenkins user's repository before the modulB build begins, and all would work.
Presumably this worked on your own machine because either you had run mvn install at least once in modulA, or because your IDE's classpath resolved the problem for you.

Resources