I tried to import some JAR files to my maven spring project using maven install plugin.
I placed the JARs in a lib folder in my base directory (where the POM.XML file is) and installed them one by one manually by running mvn install.
My xml looks like:
EDIT:
<dependency>
<groupId>com.keydoxWeb</groupId>
<artifactId>keydox</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>myPath\codecs.jar</systemPath>
</dependency>
<!-- and so on.. -->
Still telling me this error:
"Should use a variable instead of a hard coded path"
To import jars to your local repo, you generally would not have to or want to edit a pom.xml file. Rather there are shell commands that you can use to import the jars to your local maven repo (typically located at ~/.m2). Said commands are described here -- looks like this:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Once you do this, you'll also have to bring the dependencies into your projects pom.xml as explicit dependencies. That will look like this:
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
...
</dependencies>
Hope it helps!
Usually you do not have to import jars manually - they are installed by maven into local repository. And eclipse needs to know where this maven repository is. You may regenerate eclipse project files via
mvn eclipse:eclipse
(or switch to IntelliJ IDEA which opens maven projects natively)
Related
I am a beginner to Maven project. In my project, I am getting the error Missing artifact com.oracle:ojdbc6:jar:11.2.0.3, even though the jar was present in my repository at the correct folder. Can anyone help with this, please?
Unfortunately, due to the binary license, there is no public repository with the Oracle Driver JAR, so you cannot just add it to your pom file.
You have to add this jar manually:
First, you have to download ojdbc6.jar from here
click jar (2.6 MB) on the middle of the page.
Then put ojdbc6.jar in some folder in your project (let's use lib).
Then you have to add this in your dependencies section in your pom.xml:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
Another option is to install this jar in your local maven repository:
mvn install:install-file -Dfile=path/to/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
And then you will be able to reference this dependency like this:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
You have to choose what's best for you.
Remove the ojdbc6 folder from the .m2 repository completely and then maven update the project in enclipse that solved my problem
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
Should solve the issue if you are using spring boot
Once you face the issue . Check in your maven user settings path . This will be a path something like :
C:\Users\ user name\ .m2\repository
Open the location and go to oracle\ojdbc6\11.2.0.3 folder and put the .jar on that location .Return back to eclipse perform maven update and your issue will be gone.
Sorry for the spelling, I'm french
I try to install with scope a jar for oracle in my project
Here my pom.xml
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<scope>system</scope>
<systemPath>C:/Users/bin/Desktop/dossier_access/instantclient_12_1/ojdbc7.jar</systemPath>
</dependency>
The maven compile didn't function
I did after (it works)
mvn -X install:install-file -Dfile=C:/Users/bin/Desktop/dossier_access/instantclient_12_1/ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar -DpomFile=C:/Users/Documents/Projets/version7/integration-archetype/batch/packaging/integration-archetype-batch/pom.xml
but mvn install gives :
[WARNING] The POM for oracle.jdbc:ojdbc7:jar:12.1.0.2 is missing, no dependency information available
[WARNING] The POM for oracle.jdbc:ucp:jar:12.1.0.2 is missing, no dependency information available
BUILD FAILURE
Thank you for your responses,
i'm beginner with Maven and I have already see on the other posts...
What i usually do is first install jdbc driver in local repository so it is available for all apps in local machine.
Then just use regular dependency tag to include it in you pom file.
Look at this quick tutorial:
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/
After installing a 3rd party into your local repo (that is what you did with mvn install:install-file) you can reference it the following way:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
And no path information is required anymore.
I have installed maven dependency using the command below
mvn install:install-file -Dfile=d2_lib.war -DgroupId=com.emc.d2fs -DartifactId=d2_lib -Dversion=1.0 -Dpackaging=war -DlocalRepositoryPath="C:\Users\kumarr23\.m2\repository"
I have added this dependency in my root pom.xml as below
<dependency>
<groupId>com.emc.d2fs</groupId>
<artifactId>d2_lib</artifactId>
<version>1.0</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
I can see when I do maven install the jars inside my final war,
when i try importing these classes from eclipse these classes are not included, Is there some thing I am missing?
I am new to maven and i am stuck here !
please advise
Please check if you have d2_lib.war file at the location from where you are running command or else mention the full path of d2_lib.war in command and try again , i believe with the command you specify it is not copying the war file since war file path is not defined properly , you can confirm this by checking if war file is copied to your local maven repository
mvn install:install-file -Dfile=d2_lib.war -DgroupId=com.emc.d2fs -DartifactId=d2_lib -Dversion=1.0 -Dpackaging=war -DlocalRepositoryPath="C:\Users\kumarr23.m2\repository"
There is a convention in maven that java code lives in a .jar file and web classes live in a .war file. When you include a dependency with the war type in your web project, maven will treat the included file as an overlay. This basically means that maven will package the contents of the dependency into your war file, however it will not include the libraries in that war as java code the way you are looking for.
When a war file is created, if the creator also wants people to get at the java code and transitive dependencies the code is based off of, they can use the maven-war-plugin to set a configuration tag of <attachClasses>true</attachClasses>. This will generate an additional artifact in the form of artifactId-version-classes.jar, along with the normal artifactId-version.war file.
When you include both the war as an overlay and the classes jar as a normal dependency, you will be able to see in your dependency tree that maven is only pulling in transitive dependencies from the jar file dependency, not the war.
In your case, you need to find the classes jar file and install it along with the war file in your local maven repository. Then you can add the classes jar to your pom.xml like so:
old pom.xml
<dependency>
<groupId>com.emc.d2fs</groupId>
<artifactId>d2_lib</artifactId>
<version>1.0</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
new pom.xml
<dependency>
<groupId>com.emc.d2fs</groupId>
<artifactId>d2_lib</artifactId>
<version>1.0</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.emc.d2fs</groupId>
<artifactId>d2_lib</artifactId>
<version>1.0</version>
<classifier>classes</classifier>
</dependency>
I have a Maven repository that has jar files I want to use locally on other projects. What is the best way to download those jar files from the Maven repo.
I went to http://mvnrepository.com/ but the jar files do not work in my build. I would like to have is the Maven build jar files, but I am not able to save them from my project in Netbeans.
Is there a way to download all the files within Maven repository?
There's probably thousands of jar files in maven central, so I wouldn't try to download all of them.
Generally, if you want to use jars found in maven repositories, you may want to start a maven project yourself; configure your pom.xml to require those dependencies, and they'll be downloaded automatically.
Most java IDEs have maven support or a maven plugin.
-- EDIT --
Here's a really quick pom.xml example from maven's website:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
If you're using eclipse, you'll probably want to m2e plugin to handle most of this for you. Plus, it will link the javadoc to those jars as well. :)
Why don't you try using Maven instead? With Maven you're able to automatically manage your dependencies easily.
It's really simple. Please check this Maven in 5 minutes so you can begin with it successfully. Any doubts, please let me know.
-- EDIT --
As soon as you learn some main concepts, like dependencies, you can simple start your projects with the following command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
After that, you can simply import to the most used IDEs like Eclipse, using:
mvn eclipse:eclipse
The tool mvn2get (https://github.com/groboclown/mvn2get) will download published Maven artifacts suitable for use in a local repository. This includes the POM files, checksum files, and signature files, as well as able to search through dependencies.
It allows for a one-line execution to download the files:
$ mvn2get.py -d my-local-repo-dir --resolve log4j:log4j:1.2.17
I wrote this script based on a similar need to download into a local repository.
The obvious answer is to suggest that you consider building your code using Maven. This will give you native support for the Maven Central repository.
But... I sense that you just want to download the files you need to a local directory?
In that case I'd suggest using the Apache ivy command-line.
Example
The files you want are listed in a ivy.xml file. For example:
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.myspotontheweb" module="demo"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.6" conf="default"/>
<dependency org="junit" name="junit" rev="4.10" conf="default"/>
</dependencies>
</ivy-module>
And ivy can populate a local "lib" directory as follows:
java -jar ivy.jar -retrieve "lib/[artifact].[ext]" -ivy ivy.xml
The advantage of this approach is that ivy can download the additional transitive dependencies of the modules you've specified:
$ find lib -type f
lib/commons-lang.jar
lib/junit.jar
lib/hamcrest-core.jar
Note:
hamcrest-core is a depedency of junit.
I am doing a project that has dependencies on some classes from the mahout and hadoop core jars. I was using javac with the classpath option to include them before, but someone suggested to me that I should use maven to build my project instead. However, I am not sure how to add the dependencies to these jar files which are located in my /usr/local directory.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.205.0</version> <!-- or whatever version -->
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
Add this to your pom:
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>hadoop</artifactId>
<version>some.version</version>
</dependency>
</dependencies>
If you have a copy of the jar to be used for say the hadoop example above, execute this command:
mvn install:install-file -Dfile=/some/path/my-hadoop.jar -DgroupId=some.group -DartifactId=hadoop -Dversion=some.version -Dpackaging=jar
Have a look at the maven documentation, especially the part on dependency management. If you want to use Maven you should get to know the basics (one of which is dependency management).
Basially you define your project's dependencies in the <dependencies> section of your pom. Look up maven central (the most common online repository) for the dependencies you want or search for other online repositories that might contain them.
If you can't find them, add the dependencies you want anyways (think of a sensible group id, artifact id and version) and try to compile. Maven will complain about the dependencies missing and provide a basic command to put those dependencies into the local repository. Copy those commands and fill in the appropriate path to the jar file and maven will deploy that dependency in your local repository.
Note that you should first look for the dependencies in an online repository since otherwise you'd have to manually deploy each new version in your local repo.