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>
Related
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)
I have a multi module Maven project. Parent project and then two other modules, one of which builds the war through its pom.xml.
Parent Project
---- Java Project
---- War Project
I build the war from parent project. There is another external war dependency in War project's pom.xml. Jars in that project are needed to build a specific profile, which is specified in War project's pom.xml. Maven cannot get those jars from war dependency. I ran the following command
mvn install:install <information about war>
to put it in local.m2 repository, but Maven doesn't pick anything from that dependency. I understand that Maven processes war dependencies differently than it does a jar dependency but I am unable to understand as to how will it pick it up? Any help will be appreciated. Thanks.
Edit
This is how I try to include the war dependency
<dependency>
<groupId>com.example</groupId>
<artifactId>my-id-artifact</artifactId>
<version>1.0.0</version>
<type>war</type>
</dependency>
Also, I would like to mention that I use that maven war dependency in <overlay> tag.
I am using appassembler-maven-plugin to create the script to run an application. That application depends on several projects and solves this dependencies using Maven. One of the project is packeged as a war.
<dependency>
<groupId>my.war.dependency</groupId>
<artifactId>project</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
The problem I have is that the appassembler is not extracting the war dependency, only the jar dependencies. So I cannot refer to the classes in this war in order to create the script calling to one of the classes inside.
Can you help me?
Thanks in advance.
Does anyone know the Maven dependency code for JMathPlot for eclipse
<dependency>
<groupId>jmathplot</groupId>
<artifactId>jmathplot</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jmathplot.jar</systemPath>
</dependency>
Error is it can't find jmathplot/jmathplot/1.0
EDIT1:
OK I put the jar file in folder
C:/Users/MyName/Eclipse/Workspace1/MyProjectName/
Next to src, target,assembly folders
I changed dependency to:
<dependency>
<groupId>jmathplot</groupId>
<artifactId>jmathplot</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/jmathplot.jar</systemPath>
</dependency>
And I get the error:
com.tradable.terminal!.plugin.storage.Tr!PluginPackageException: PluginId: com.NoviumResearch.ValueAtRisk, The resource lib/jmathplot.jar does not exist
It seems to be trying to look in "lib" not sure why
With your Maven snippet you're telling Maven to get the jar from this path: {project folder}/lib/jmathplot.jar
You can solve the issue creating a lib folder in the Eclipse project and then copy there the jmathplot jar.
You can download the jar from here: http://jmathplot.googlecode.com/svn/trunk/jmathplot/dist/jmathplot.jar
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.