DEV Community

Marcos Henrique
Marcos Henrique

Posted on

3 3

Building 3rd party JARs in Spring (Maven project)

I had an external .jar that cannot be imported from public repositories using pom.xml, it's XPTO.jar.

I was able to run the project locally from my IDE and everything worked perfectly. Refer to the library after downloading it as follows:



<dependency>
<groupId>com.xpto.lib</groupId>
<artifactId>XPTO</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/XPTO.jar</systemPath>
</dependency>

Enter fullscreen mode Exit fullscreen mode




When I run mvn clean package to create my .jar file and try to run the created .jar, an error will pop up.

I was facing this error and about getting crazy before finding this solution.

Miracle Solution 🙆‍♂️🙆‍♀️

In your pom.xml just add this <includeSystemScope>true</includeSystemScope> like this



<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>

Enter fullscreen mode Exit fullscreen mode




The IDE can easily see the scope of the system by default, however when generating our build we have to force the maven to see this same scope.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
khmarbaise profile image
Karl Heinz Marbaise

The last sentence is not accurate. You are forcing the spring-boot-maven-plugin to consider system scoped dependencies not Maven itself. Apart from that the usage of <scope>system</scope> will produce a WARNING during the build (since maven.apache.org/docs/3.5.2/releas...).

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️