Reputation: 267
I have a maven project (Proj1). In my java class I have to call method of another maven proj (proj2).
Here I get various compile time errors as that method is not available in my current project (proj1). In order to resolve that I took whole method code and paste that method in my current java class. Now that method is available in my project. But then that method again calls few other code from other classes which are again not available in my current project. Again I needed to copy and paste all the dependent code from other classes. This goes on and on and circular dependency is there so just wondered how I can resolve this error. I have couple of options in order to resolve this.
Now my question is
Upvotes: 0
Views: 10433
Reputation: 11251
Make all you projects use maven. Add pom.xml to the root of your project with following header(I don't know your packaging structure so com.sachin
is placeholder. You can ask IDE to add maven support for you):
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sachin</groupId>
<artifactId>Proj2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Proj2</name>
Add same header for Proj1
and add dependency from Proj1
to Proj2
:
<dependency>
<groupId>com.sachin</groupId>
<artifactId>Proj2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
After maven build
Proj2
will be added as jar dependency to Proj1
.
if I include only proj2.jar in my code then will it resolve all the dependency?
If your proj2.jar
has pom.xml
with dependencies that proj2.jar
use - then yes they will be fetched during building of proj1
using maven.
Official documentation about Maven Dependency Mechanism
Upvotes: 5