I am trying to add a jar file to the Maven dependency in my project. The settings.xml is configured to set the repository to a public repository. But this particular jar is not present in that repo. As i have the jar in my lib folder, how can i configure the Maven dependency to take this jar?
Have a look at system dependencies.
You basically need to define <scope>system</scope>.
<project>
...
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
...
</project>
This is if you don't have your own hosted artifact repository server such as Nexus, Artifactory or Archiva.
If you do, then as Karl-Heinz suggested, you would be better off placing it there, as it's not good practice to commit binary artifacts to version control.
Another option is to set up a repository that is backed by a directory inside your project, per this answer: https://stackoverflow.com/a/2230464/433789
Changing pom.xml worked for me (jar in "/lib" directory in the root project folder) :
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/gson-2.8.6.jar</systemPath>
</dependency>
The best solution is to start using a repository manager like Nexus and put it there. Or you can use the non-maven-jar-plugin.
Related
Library depends on library, which missing in maven central (error 404 missing library). I tired to download the same library from an external source and placed into local Maven Repository, but it's not working. How can I solve this problem?
The following artifacts could not be resolved: javax.media:jai-core:jar:1.1.3, com.sun.media:jai-codec
:jar:1.1.3: Failure to find javax.media:jai-core:jar:1.1.3 in http://repo.maven.
apache.org/maven2 was cached in the local repository, resolution will not be rea
ttempted until the update interval of central has elapsed or updates are forced
If I adds these libraries in pom of my project(just for testing local repo), it's ok (from local repo). Problem, that another library depends on them.
My pom.xml:
<dependency>
<groupId>de.intarsys.opensource</groupId> //lib in maven central
<artifactId>jPodRenderer</artifactId> //depends on libs below
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>javax.media</groupId> //in local repo
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.media</groupId> //in local repo
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
Can you just try it out.
I'm not sure I understood your question.
Pom.xml
<dependency>
<groupId>com.sun.media</groupId> //in local repo
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>de.intarsys.opensource</groupId>
<artifactId>iscwt</artifactId>
<version>5.5</version>
</dependency>
Make sure that the version of jar file you download has the same version with the file in pom.xml.
Make sure that you put the jar file in the correct directory.
The fastest solution is to add a Maven repository in your project source code. See here for an example on how to add a library to a custom maven repository :
http://david-codes.blogspot.com/2014/03/maven-add-custom-repository-in-your.html
There's a difference in the name:
maven was searching for jar-core, but you refer to jai_core
The first one is available on https://repository.jboss.org/maven2, the second one on maven central https://repo1.maven.org/maven2
I am trying to include a zip file from nexus repository to my project during packaging using the maven assembly plugin. This zip file has YAJSW and other custom scripts. The maven assembly can build a tar.gz package now, but how do I include a zip file from nexus repository. There is a pom for that zip file. Should I just include that as dependency? Is this the correct plugin or should I use another plugin.
Thanks.
Add the dependency of the zip file like the following:
The following is an example for archive which has been created by maven-assembly-plugin:
<dependency>
<groupId>the.group.id</groupId>
<artifactId>the-artifactid</artifactId>
<version>1.0</version>
<type>tar.gz</type>
<cassifier>bin-unix</classifier>
</dependency>
<dependency>
<groupId>the.group.id</groupId>
<artifactId>the-artifactid</artifactId>
<version>1.0</version>
<type>zip</type>
<cassifier>bin</classifier>
</dependency>
The classifier in those cases is comming from the assembly-decscriptor-id in the project which creates the archive. Apart from that it is important to define the type.
Add a dependency to the zip with the respective GAV (group/artifactId/version).
(Without seeing your pom.xml it's a bit hard to say more).
I have one project jar oauth.
I want to add it in another maven project . I tried to change pom.xml file but no effect. Can anyone please suggest me?
I tried to add following dependency in my pom.xml file:
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapps/WEB-INF/lib/auth.jar</systemPath>
</dependency>
With the assumption that you have that auth.jar in your local repository (as it builds fine).
Why don't you give a try like this.
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Honestly speaking I don't prefer to give the jar location in my pom file and using scope as system, I leave this task to handle by Maven to resolve all the artifacts either by searching in local maven repository first(/.m2) or in MAVEN CENTRAL REPO if it is a 3rd party jar.
I have a dependency problem with maven. I used to have saxon 8.7 that is located on maven central. Then, I had to upgrade to the latests saxon-b 9.1.0.0 which is only partially on maven central.
This is a snippet of my dependencies:
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon-dom</artifactId>
<version>9.1.0.8</version>
<scope>runtime</scope>
</dependency>
The first artifact 'saxon' is available on maven central, but the secon 'saxon-dom'. Here is the artifact I want.
Can I tell maven to download the "jar" file or am I obliged to download the jar and publish it locally on my maven repo to use it as a dependency?
Did not expect to resolve this so easily :
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
<classifier>dom</classifier>
</dependency>
Basically, I can get the dependencies that are "attached" to the 'saxon' artifact using the classifier tag. Did not know about this and I found out that the tag existed when I searched for 'saxon' on Sonatype repository (which is quite good). It gave me the dependency snippet above.
Reference : http://maven.apache.org/pom.html
If the required version is not in the repo, then yes you need to do one of the following alternatives
Search for a public repo containing the required version of jar. And add the repo to your pom.xml file. OR
Download it manually, and install it locally on your machine, to help the project build completely.
I'm working on a multi-project, and right now I have a structure that resembles this (actually there are a couple of jar projects and a couple of war projects)
/myProj
|_______projA (jar)
| |____pom.xml
| |____target/jar files
|_______projB (war)
| |___pom.xml
| |___web-inf/lib/jarfiles
|_______projEar
| |___pom.xml
|___pom.xml
What I want to achieve, is to make projA and projB to read their dependences from a common shared folder, instead of keeping their own copy.
Actually, I don't really care where they read them from at compile time, but when I package my EAR file, I want each jar/war to appear just once, hence reducing the EAR size.
I've tried declaring the dependencies on the parent pom, declaring the dependencies as and some other things, but so far I haven't achieved this.
Is there an easy way to achieve this? Any simple maven plugin?
Thanks in advance.
You should be able to do this by adding the JAR as a dependency to your EAR's pom.xml:
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
...and specifying the dependency as provided in your WARs' pom.xml:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
If Maven/other tooling has already copied the JAR to your WEB-INF/lib directory, you may need to delete the file manually prior to rebuilding.
This should result in an EAR of the form:
META-INF/MANIFEST.MF
lib/myapp-utils-0.0.1-SNAPSHOT.jar
META-INF/application.xml
myapp-web.war
When you are moving to Maven, you should not store the dependency JAR's in your code base. I would suggest you to create a central Maven repository which will contain all the dependencies.
Refer mvn install to first install these artifacts into the local repository. Also, you can refer to the maven central repository to get artifacts while building.
What you need to do is: remove all the dependency jar's from the source code, and all their dependency in the pom.xml. These would be downloaded and packaged from the maven central repository as and when required. Set the Dependency Scope of the artifacts accordingly.