0

I want to create module based project. and want to create spring projects and export these as jar and then import that jars in my base project is it possible?

Hadi
  • 1
  • Yes. It is possible. You can do a `mvn clean package` to your current project. Jar file will be generated. You can use import the jar to your another project locally or you can use the maven artifact import in the pom file of another project. Also see [importing local jar](https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project) – Sabesh Jan 14 '19 at 07:20

1 Answers1

2

Since you've added the tag maven I suppose you use it in your project.

If you use Spring Boot

If you build a Spring Boot application the output is a fat jar in the default case and it is not for import to any other projects.

But you can use the repackage plugin in your spring boot module to create a simple jar too!

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>boot</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>

In this case you will have

  • A projectname-0.0.1-SNAPSHOT-boot.jar (boot comes from the classifier I've defined in the plugin, you can choose any other name) which is the runnable Spring Boot fat jar.
  • A projectname-0.0.1-SNAPSHOT.jar which can be imported to any other projects.

If you don't use Spring Boot

Then simply maven install your project with maven and add the module as a dependency to the other module's pom.

The dependency's pom:

...
<groupId>com.your.group</groupId>
<artifactId>example-module</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
...

And your dependent module's pom:

...
<dependencies>
...
    <dependency>
        <groupId>com.your.group</groupId>
        <artifactId>example-module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
...
</dependencies>
...
Szilárd Fodor
  • 354
  • 2
  • 9