Reputation: 165
I have a compilation error in one of my projects
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
because it does not find all the classes from another project that I already included using
<dependency>
<groupId>com.laberint</groupId>
<artifactId>laberint-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
and I don't have any compilation problems from Eclipse. I already deleted all the repository.
The errors are because a missing classes that all are in the laberint-core
artifact. I already deleted the whole repository folder
I also installed the jar
mvn install:install-file -Dfile=laberint-core-0.0.1-SNAPSHOT.jar -DgroupId=com.laberint -DartifactId=laberint-core -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
Upvotes: 0
Views: 704
Reputation: 1358
As you stated in your comment you are developing the laberint-core
project in the same Eclipse
workspace as the project you are trying to build. The problem you have is that while Eclipse
knows each project in your workspace and can resolve those project dependencies, Maven
does not have this Information which means that it searches the repositories (your local one in ~/.m2
and Maven Central
) for the dependency.
As you said, you have already installed the laberint-core
project to your local Maven
repository via mvn install
. That's why Maven
can find the dependency at all and you do not get a dependency could not be resolved
exception but I would guess that you installed the dependency some time ago and so some of the classes that your created in the Eclipse
project after installing are missing.
There are two ways how you can resolve this issue
jar
each time before you build the main projectThis means some more manual overhead when you are building the main project but it can be automated if you are only building in Eclipse
and not directly from the command line.
This would basically be a third project that consists only of a pom.xml
file that looks somewhat 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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.laberint</groupId>
<artifactId>aggregator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>relative/path/to/laberint-core</module>
<module>relative/path/to/laberint-main</module>
</modules>
</project>
To build the project you would then call the goals you called on the main project before on the aggregator project. Basically if you called mvn package
before from the root directory of the main project you would now change to the root directory of the aggregator project and call mvn package
. By convention the aggregator pom should lay in the parent directory of its modules.
Upvotes: 0
Reputation: 5591
Simply create a jar from your another project and add it in local lib directory of your current project. Another option is install the jar file in to your local maven repository like below:-
mvn install:yourlocal-jarfile
-Dfile=<path-to-your jar>
-DgroupId=<group-id> --> the group that the file should be registered under
-DartifactId=<artifact-id> --> give a artifact name to your jar
-Dversion=<version> --> version of your jar file
-Dpackaging=<packaging> --> jar
-DgeneratePom=true
Also you can try with below option:-
<dependency>
<groupId>com.laberint</groupId>
<artifactId>laberint-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<systemPath>/pathto/yourJar.jar</systemPath>
</dependency>
Hope this will help your. Good Luck!!!
Upvotes: 1