I am using maven to build my java project.
I have a library jar named my.jar used as my project's dependency. However, it is not available in the remote central repository. So, I would like to put the jar file under my project. So, I created a folder named my_repo/ under MyProject.
The directory structure of MyProject looks like this:
MyProject/
my_repo/
my.jar
pom.xml
But I have no idea how could I define my pom to find this particular dependency under MyProject/my_repo/my.jar ?
Could someone please help me for my scenario? By the way, I have also some other dependencies defined in my pom.xml, they are available in the remote central repo.
Using the system scope. ${basedir} is the directory of your pom.
<dependency>
<artifactId>..</artifactId>
<groupId>..</groupId>
<scope>system</scope>
<systemPath>${basedir}/my_repo/my.jar</systemPath>
</dependency>
The recommended way is usually to use a Maven Repository Manager (e.g. Nexus) and then deploy your library to this Maven Repository Manager.
See here for how to set up the settings.xml file:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html
How to create maven dependency for your local jars..
1)Create a maven project of the program of which you have to create the jar.
2)Add required groupid and artifact id and version no.
3)Then after writing the java files export it as a jar.
4)Now open other project in which you want to add local jar dependency.Go into its pom.xml and add dependency with the group id,artifact id and version which u had entered in the jar project.
5)Maven clean and install.Now that jar file will be available in your local repository. :)
Related
I have a situation like below:
1. I have a JAR which is available in cloud URL
2. I want to download the JAR and use it as a JAR in my project.
3. For downloading I am using Maven ant run plugin and putting it in specific folder of the project.
Now I want to add the jar to classpath file via pom.xml
I have downloaded the JAR from the cloud and placed it in specific folder.
Is there anyway in which as soon as I download the JAR from cloud, I can modify my classpath by adding a classpathEntry through POM.xml?
There are various ways but the easiest option is to download the file to your local repository with the file path matching to your dependency's groupId, artifactId and version.
Assuming below is the dependency that you are trying to add to you pom.xml
<dependency>
<groupId>your.company</groupId>
<artifactId>downloaded-file</artifactId>
<version>1.0.0</version>
</dependency>
then download the file to /your/company/downloaded-file/downloaded-file-1.0.0.jar
I have a Maven project where I've imported an external JAR (via Build Path) and it's under Referenced libraries folder. How can I import it within my .java class file? I mean literally the code "import ??". The class is in com.example.demo package. Do I need to add a dependency somewhere (pom.xml)?
If that's a maven project the best way would be to add that jar as a dependency in your pom.xml dependencies section. Then when you compile with maven it will use that dependency. In order to build properly in eclipse you need to call mvn eclipse:eclipse and it will sync the dependencies in the pom.xml with the build paths of the eclipse project.
If the jar is not a common one and you cannot add find it in the public repo (for example some jar that you have created) then you need to first install it in your maven repository with the required group and artefact name. Otherwise if it is some library which is publicly available in the central maven repository maven will download the required jar and install it in your local repository for you
I'm trying to produce a Maven-compatible artefact using bazel. I noticed that mvn puts some files inside META-INF directory in JAR archive (file.jar/META-INF/maven/groupId/artifactId/pom.xml and file.jar/META-INF/maven/groupId/artifactId/pom.properties)
Questions:
Are they needed to be able to successfully depend on my artifact from another project? I know you can disable them via a config option in pom.xml ref, which leads me to believe that you don't.
Are they used by mvn in any case whatsoever?
Can I use pom.xml inside on the JAR instead of pom.xml near my artifact in Maven repo?
We have several jars in your Maven repository that do not contain a pom.xml. For maven, the revelant pom.xml is the one that is outside your artifact. In Nexus, you deploy a jar always along with a pom.xml and that is the one that counts.
So you need to publish a pom.xml along with your jar if you want to use it from Maven, but you do not need to put it inside. AFAIK you cannot change this behaviour.
I have a maven based project where I have to invoke an external jar (say country.jar)
I added this jar on src/lib folder and did below setting in pom.xml
<dependency>
<groupId>country-stubs</groupId>
<artifactId>country-stubs</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\country.jar</systemPath>
</dependency>
While Running my application I am getting error
java.lang.NoClassDefFoundError: com/fsg/bpo/webservices/countWebService
Location(com/fsg/bpo/webservices/countWebService) is referring to the class present under country JAR
Do I need to add few more settings to configure external JAR in maven ?
If you are using scope system you are saying it is a provided jar later on. I would use runtime maybe. Have a look at maven scopes
If it is web application then your jar won't get bundled inside your war file. Then you will get this issue. you can directly copy this country.jar to your WEB-INF lib folder and use that system path.
1st u need to add ur external jar to ur local maven directory..
using below command on cmd..
mvn install:install-file -DgroupId= -DartifactId=aes-decryption -Dversion=1.0.0 -Dpackaging=jar -Dfile=./target/aes-decryption-1.0.0.jar -DgeneratePom=true
I have downloaded a source jar file of OrientDB from maven repo, orientdb-source.jar. The structure is:
orientdb-source.jar/com/orienttechnologies/orient/core/...
/META-INF/...
I have installed m2e plugin. But I dont know to import this jar file as a maven project. I dont want to import this jar file as an external jar. Can anyone help me?
It sounds like you want to use/access this artifact within a maven environment.
If all you want to do is use the jar in your class path you should add the jar as a dependency in your project's pom file. You may also need to add the repository reference to the pom if the jar is coming from a private repository. Once your pom file is modified with the reference to the jar then you can select your project and click "Maven -> Update project dependencies". Maven will download the jar and modify your class path.
If you want to actually look at the source then look for a reference on the 3rd party's web site to the repository containing the source code. Use the appropriate Eclipse plugin (git, svn, etc.) to point to and checkout the version of the source.
If you want to import the jar on your project, put this on your <dependecies> tag in pom.xml on root of your project:
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb</artifactId>
<version>1.3.0</version>
</dependency>
From Maven Repository
This will import the jar on your project lib folder.
Anyway, if you want to modify code from this lib, you need to create a new Project with content of this jar. Package as jar on maven and put as dependencie.