I need to add a jar not exist in publi repo to my maven project i have using system scope like this :
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${user.home}/jars/my.jar</systemPath>
</dependency>
This solution working fine in local machine but not in distant server. when i google it i find that system scope is aleardy a bad practice so there is another solution to add a jar to project?
You have two options here.
First:
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
Second:
Install this jar in your local repository and it will be included in your built project.
You can add jar in you local repository like this:
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
Edit your pom.xml
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
</dependency>
Related
I have set MAVEN paths and variables. I am able to run a sample SpringBoot project in Eclipse but what I want is I have a custom jar and I am using classes from that jar in my Spring Boot Project. When I include this custom jar and build the SpringBoot application, I get the following errors
[ERROR] The goal you specified requires a project to execute but there
is no POM in this directory (D:......\SpringBootDemo\target).
Please verify you invoked Maven from the correct directory. -> [Help
1]
org.apache.maven.lifecycle.MissingProjectException: The goal you
specified requires a project to execute but there is no POM in this
directory (D:......\SpringBootDemo\target).
Please verify you invoked Maven from the correct directory.
My POM.xml is as follows:
<groupId>com.demo</groupId>
<artifactId>SpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringBootDemo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Am I missing anything?
Any help will be greatly appreciated.
Thanks
Sometimes you will have 3rd party JARs that you need to put in your local repository for use in your builds, since they don't exist in any public repository like Maven Central. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Apache Maven. To make this easier, and less error prone, we have provide a goal in the maven-install-plugin which should make this relatively painless. To install a JAR in the local repository use the following command:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
With version 2.5 of the maven-install-plugin it gets even better. If the JAR was built by Apache Maven, it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default. In that case, all you need to do is:
mvn install:install-file -Dfile=<path-to-file>
From a Maven Guide to installing 3rd party JARs.
I am trying to get dependency version at run time from command line in maven, but it does not reflect into artifact pom at maven repository.
My project pom is like :-
<parent>
<groupId>com.company.project</groupId>
<artifactId>parentProject</artifactId>
<version>5.6.0.14</version>
</parent>
<properties>
<my.version>${my.version}</my.version>
</properties>
<groupId>com.company.project</groupId>
<artifactId>childProject</artifactId>
<dependencies>
<dependency>
<artifactId>someArtifact_one</artifactId>
<groupId>com.company.project</groupId>
<version>${my.version}</version>
</dependency>
<dependency>
<artifactId>someArtifact_one</artifactId>
<groupId>com.company.project</groupId>
<version>${my.version}</version>
</dependency>
</dependencies>
My command is like - mvn install -Dmy.version=5.6.0.12, project is build successfully and uploaded at maven repository , but when I verify artifact pom.xml at maven repository its same as.
<dependency>
<artifactId>someArtifact_one</artifactId>
<groupId>com.company.project</groupId>
<version>${my.version}</version>
</dependency>
I think it should be like below at maven repository.
<dependency>
<artifactId>someArtifact_one</artifactId>
<groupId>com.company.project</groupId>
<version>5.6.0.12</version>
</dependency>
How could I resolve this issue, or if someone has some other solution for this issue please suggest.
This is mainly because, you are over-writing the value you pass in goal -Dmy.version=5.6.0.12 with the properties tag in pom.xml. To fix it, Either you can remove this properties tag completely (or) set it as below
<properties>
<my.version>5.6.0.12</my.version>
</properties>
Another way is to pass the arguments as : -Darguments="-Dparam1=val1 -Dparam2=val2" in CI environment
As mentioned in this article : enter link description here
I have a simply POM like this :
<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.sim</groupId>
<artifactId>log4j</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.sim</groupId>
<artifactId>sim-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../sim-java/pom.xml</relativePath>
</parent>
<name>log4j</name>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
</dependencies>
I run mvn clean package on this project and a JAR is created as expected.
When I navigate into this JAR, I thought that I would see a JAR named log4j-1.2.17.jar inside it but it's not the case.
Using dependency with compile scope does not include JAR into packaging version of project ?
Thank you for clarification
The jar:jar plugin of maven just compiles your source and bundles it into a jar. Just like building a jar out of ant or bare hands, no dependency jars will be bundled in the jar. Jars cannot have dependent jars bundled inside them and even if they did, they cannot be loaded by the default class loader.
If you are looking to build a ejb-jar, then you might want to consider a EJB plugin
Check this link for various plugins that you can exploit.
I have a simple maven plugin which in turn depends on parent pom file. The parent pom file has ten (10 number of) 3rd party jar dependencies which have been installed in my local repo using the following command.
mvn install:install-file -Dfile=foo.jar -DgroupId=com.foo.bar -DartifactId=foo1.jar -Dversion=1.1.0.0 -Dpackaging=jar
Similarly I have installed all the other 9 jars to my local repo. This is the uber pom.xml file.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.bar</groupId>
<artifactId>maven-uber-pom</artifactId>
<packaging>pom</packaging>
<version>1.1.0.0</version>
<name>maven-uber-pom</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo1.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo2.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo3.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo4.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
:
:
</dependencies>
I am trying to reference this uber pom in my plugin's pom.xml file by the following:
<project>
<parent>
<groupId>com.foo.bar</groupId>
<artifactId>maven-uber-pom</artifactId>
<version>1.1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.bar</groupId>
<artifactId>foo-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1.0.0</version>
<name>foo bar plugin</name>
<url>http://maven.apache.org</url>
</project>
After this I try installing my plugin using the pom.xml file by
mvn install <command>
Maven tries to download the 3rd party artifact dependencies from central repo http://repo1.maven.org/maven2 and subsequently fails. As there is no artifact which such co-ordinates which can be found in the central repo.
I have also tried using the uber-pom as a plugin dependency since I was desperate. Any ideas?
By default Maven will search for dependencies in your local repositories first. If it doesn't find, it will then search on your global/custom repositories (by default only the central repository is set). Did you run mvn install on uberpom? And if so, check if it's path is correct in your local repo.
I'm not sure if you just forgot to adapt this to your example, but "uberpom" definition has com.foo.bar as groupId and the usage on your plugin has com.oracle.weblogic.test. It's probably a typo though. I also suppose that all your 3rd party dependencies were installed correctly (check their pom).
And just for the sake of it, check if <localRepository> is set in your settings.xml. Usually you don't have to set this, but give it a shot.
I'm not any expert but I hope it helps!
The groupId in your parent POM and the groupId in the reference to the parent POM don't match. The groupId, artifactId, and version must match exactly in order for Maven to find the parent.
Try mvn install -o to force offline mode. Out might point out the problem.
When you ran the install-file command, did you specify generate pom and generate checksums?
Manually check your maven repo for the jars to see if they installed properly.
I have two projects:
Project-Core
Project-Source
Project-Core POM.xml:
<groupId>com.company</groupId>
<artifactId>project-core</artifactId>
<packaging>jar</packaging>
<version>2.1</version>
Project-Source POM.xml:
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>project-core</artifactId>
<version>2.1</version>
<type>pom</type> (have tried leaving it out)
</dependency>
</dependencies>
I've done mvn clean install on Project-core, which installed the artifact in the local maven repository.
I am able to CD to Project-source and use mvn clean install (this installs Project-Source in the local maven repo as well), but I'm having trouble with NetBeans not finding the classes I need (from Project-Core) inside Project-Source.
What's a proper way of linking multiple projects? Since Project-Core produces a jar and that jar is installed in the local repository, it looks logical to only have to list that jar as a dependency on my Project-Source project. Is anything else needed?
You specified that the dependency "project-core" is of type "pom", but from the declaration it has packaging "jar" ?
Try:
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>project-core</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
Edit:
I've created a simple test project which worked just fine to use in Netbeand 7.0.1. Take a look and see if it gives you any hints.Code snippet