Nicolasome
Nicolasome

Reputation: 396

Adding a local Maven project as a dependency in another local Maven project

I have a local java application that I have recently converted to a Maven project. My goal is to add my recently converted maven project to another Maven project as a dependency in Eclipse STS.

The temporary path of the recently converted maven project is C:\Users\nconnor2\Desktop and the path of the soon-to-be parent Maven project is C:\Users\nconnor2\Desktop\adoudrepo.

I'm really struglling to wrap my head around how maven works when dealing with local maven project.

The pom of my new maven project is

<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>TB2TUBSync</groupId>
  <artifactId>TB2TUBSync</artifactId>
  <version>1.5</version>
</project>

The pom of my soon-to-be parent Maven project is

<?xml version="1.0" encoding="UTF-8"?>
<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.bellmts</groupId>
    <artifactId>test</artifactId>
    <name>TB2TUBSyncWeb</name>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>

What I have been trying to do is to include my new maven project as a module in my soon-to-be parent maven project but I get an error that I can't include a module in another maven project with war packaging.

At the end of the day I need to access methods from TB2TUBSync (new maven) in TB2TUBSyncWeb (soon-to-be parent maven).

Upvotes: 0

Views: 552

Answers (1)

ingyhere
ingyhere

Reputation: 13861

You'll want to leverage the WAR Plugin to generate both JARs and the WAR file, then you can publish the jars to your local repository with mvn clean install. At that point you can import them into the other POM with dependency resolution.

It's detailed at https://eureka.ykyuen.info/2009/10/30/maven-dependency-on-jarwar-package/ .

Upvotes: 1

Related Questions