I have my own maven project:
/path/to/my_project/
pom.xml
/src/main/java/com/my/MyProject.java
MyProject.java contains a dependency to external class:
package com.my;
import com.other.ExternalClass;
class MyProject {
ExternalClass d;
}
External class is located in another maven project:
/path/to/another_project/
pom.xml
/src/main/java/com/other/ExternalClass.java
How to specify dependency such that mvn install command executed on my project would not throw error package com.other does not exist
You mvn install the project another_project
You add a <dependency> entry with the correct coordinates (groupId, artifactId, version) of another_project to the pom.xml of my_project.
Then you mvn install the project my_project.
Related
I created a new project using the following maven command:
mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=com.github.xlongshu.maven -DarchetypeArtifactId=archetype-quickstart
I then entered the following values:
'groupId': com.example.mycompany
'artifactId': myproject
'version' 1.0-SNAPSHOT: :
'package' com.example.mycompany: :
I received the following warnings:
[WARNING] CP Don't override file /Users/user/workspace/myproject/pom.xml
[WARNING] CP Don't override file /Users/user/workspace/myproject/README.md
I then import this new project into Eclipse Oxygen 4.7.3a (no update available for now) using Import... > Existing Maven Projects
And I then get the following errors (under Eclipse in pom.xml file) :
Project build error: 'dependencyManagement.dependencies.dependency.systemPath' for jdk.lib:jconsole:jar must specify an absolute path but is ${env.JAVA_HOME}/lib/jconsole.jar pom.xml /myproject line 1 Maven pom Loading Problem
Project build error: 'dependencyManagement.dependencies.dependency.systemPath' for jdk.lib:tools:jar must specify an absolute path but is ${env.JAVA_HOME}/lib/tools.jar pom.xml /myproject line 1 Maven pom Loading Problem
However, from command line, everything works well:
mvn validate
mvn compile
The error seems to come from parent POM:
<dependency>
<groupId>jdk.lib</groupId>
<artifactId>jconsole</artifactId>
<version>${jdk.version}</version>
<scope>system</scope>
<systemPath>${jconsolejar}</systemPath>
</dependency>
where jconsolejar property is defined as follow:
<jconsolejar>${env.JAVA_HOME}/lib/jconsole.jar</jconsolejar>
What could I do to solve this error in a clean and efficient way ?
(Maven version: 3.5.3)
I had the same issue when I use a variable to specify a system path for a local jar.
The solution I use is to replace the directory with an absolute path such as
C:\Users\XXXX\eclipse-workspace\PROJECTNAME\src\main\webapp\WEB-INF\lib
The error is gone but a warning is left because this is not recommended
I want to build one jar that includes a child module which depends on other package of my own project.
The output one jar should include all the related class (both from jar and my own project's classes).So the child module's classes is the base classes that should be included in the output jar,and these import some classes of my own project.All the related classes in my own project should be included.
for more detail please visit How to automatically collect all related class into one jar (use maven)?
Here is what I already find:
<project>
<dependencies>
<dependency>
<scope>system</scope>
<systemPath>D:\how\to\write</systemPath>
<groupId>how.to.write</groupId>
<artifactId>how-to-write</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>java-source</type>
</dependency>
</dependencies>
</project>
The error message is : Could not find artifact how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT at specified path D:\how\to\write
the path D:\how\to\write contains my own project's classes that could support the build
Your maven dependency will look for a jar file with name how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT in D:\how\to\write directory. Since you do not have one, the build will fail.
If your own project does not use maven, then you should create a jar file and place it in D:\how\to\write location and rename it to how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT. Then your build mvn clean install will be success.
The command for creating jar file is jar cf jar-file input-file(s).
Have a look at this page on how to create a jar file
I'm using eclipse Luna, maven 3.0.5 and Java 6. I'm working on 2 projects in eclipse.
Project A
package com.project.one;
public class Test{
public String name="David";
}
Project B
package com.project.two;
import com.project.one.Test;
public class Hello{
public static void main(String[] args){
Test test = new Test();
System.out.println("Hello "+test.name);
}
}
I add project A to project B using Build Path (Right click on project B's folder in eclipse --> properties --> build path --> projects --> add), it's success but when the project B i compile using mvn clean package i got an error, and it said
BUILD FAILURE
[ERROR] D:\xxx\Hello.java:[2,20] package package com.project.one does not exist
also line 5 and 6 is error (cannot find symbol)
So anyone can help me to resolve it?
Here's my workspace:
You need to set maven dependencies explicilty. SO in projectB pom,xml you should explicilty mention your compile/run time dependency on project a
<dependency>
<groupId>com.project</groupId>
<artifactId>projectA</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
I am able to create an object for a class in a jar file, which is another module.
I created a new java project with a main class, added the jar to the lib folder and I am able to create the object for that jar's class(com.canonical.client), while running the main class as a java application.
Now, I have converted this java project to maven. While I try to clean and install, I am unable to build successfully. The error given is " package com.canonical.client does not exist".
After Jespers's suggestion I am able to build the project. I am getting the following exception, while calling method which creates client object. In that jar, it looks for some other jars.
java.lang.ClassNotFoundException: ch.qos.logback.core.Context
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at com.mmf.controllers.PickEquifaxController.handleRequestInternal(com.mmf.controllers.PickEquifaxController:33)
My manifest file's first 2 lines in that jar are as follows, its refering 118 jars actually,
Manifest-Version: 1.0
Class-Path: . canonicalclient_lib/activemq-camel-5.8.0.jar canonicalclient_lib/activemq-core-5.6.0.jar
canonicalclient_lib/activemq-pool-5.6.0.jar canonicalclient_lib/activemq-protobuf-1.1.jar
What I need to do to get a solution in this. pls advice.
You can install your JAR in your local Maven repository with a command like this:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
where you'll have to fill in your own group id, artifact id, version and packaging - the packaging will most likely be jar - for example:
mvn install:install-file -Dfile=myjarfile.jar -DgroupId=com.canonical
-DartifactId=client -Dversion=1.0 -Dpackaging=jar
After doing this, you can use it like any other Maven dependency, by specifying the dependency using the group id, artifact id and version in your pom.xml:
<dependency>
<groupId>com.canonical</groupId>
<artifactId>client</artifactId>
<version>1.0</version>
</dependency>
You can add your custom jar by this way in POM.xml
<dependency>
<groupId>com.canonicalclient</groupId>
<artifactId>xxx</artifactId>
<version></version>
<systemPath>${basedir}/lib/xxx.jar</systemPath>
</dependency>
I'm writing assignment on coursera.org Java course. I'm using Maven and I have external jars that I have to use in this course (course requirements).
This is part of my pom.xml:
<dependency>
<groupId>org.coursera.algs4part1</groupId>
<artifactId>stdlib</artifactId>
<version>1.0</version>
</dependency>
I can't make java compiler import the external jar file. Below, following errors occur:
The import org.coursera.algs4part1.stdlib cannot be resolved
But I've successfully added the jar to maven:
What am I missing?
You need to do the following steps if you have a eclipse-maven plugin installed.
Run the command mvn eclipse:eclipse
Go to Project Properties > Build Path > Libraries tab > Add Variable... button > Configure Variables... button > New button. Enter the variable name as M2_REPO and its value/path to the Maven Repository path (Usually it's like C:\Users\<username>\.m2\repository.)
1.create a folder src\lib and paste your jar file
2.your pom.xml should be like this.
<groupId>org.coursera.algs4part1</groupId>
<artifactId>stdlib</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\stdlib.jar</systemPath>
</dependency>
Hopefully this will solve your problem and for more details visit http://noexceptionfound.blogspot.in/