Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell Maven to bundle dependent jars

Tags:

java

maven

I want to use Jmathplot.jar

I tried to put it as a dependency

<dependency>
      <groupId>jmathplot</groupId>
      <artifactId>jmathplot</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/jmathplot.jar</systemPath>
    </dependency>

but when installing I get this error:

Some problems were encountered while building the effective model for com.NResearch:dable-start-tRisk:jar:0.1-SNAPSHOT 
[WARNING] 'dependencies.dependency.systemPath' for jmathplot:jmathplot:jar should not point at files within the project directory, ${project.basedir}/lib/jmathplot.jar will be unresolvable by dependent projects @ line 44, column 19 

How can I get around this please?

EDIT1:

I cannot change Maven to include all dependent jars into a single jar. As this is uploaded to a web project.

like image 507
ManInMoon Avatar asked Jan 28 '26 09:01

ManInMoon


1 Answers

"Dependent" is using your project, "dependency" is used by your project.

The real error here is that jmathplot.jar is in a folder that can really only reliably be found by your project. Even though your dependents know how to find your artifact in the local repository, they won't know where the sources are for your artifact, hence won't be able to find lib/jmathplot.jar. You can fix that by changing the systemPath to an absolute path. It can still be parametrized, but then please use properties rather than implicit properties (such as ${project.basedir}.

It'd be better to get rid of the systemPath dependency, by installing jmathplot into a company repository, so it can be used alike 'normal' artifacts. But that may not be a useful option if you have to distribute your artifact out of the reach of your company repository. It would even be better if jmathplot would just get deployed to the Maven central repository.

As a last resort you may choose to bundle the dependencies (not the dependents). You can do this:

  • Using the Maven Shade Plugin. It lets you choose which packages to include which may be useful to bundle only jmathplot (and not other dependencies).
  • Using the Maven Assembly Plugin. It has a predefined descriptor for "JAR with dependencies" which would fit your use case. You could create your own descriptor off of that example and set dependencySets.dependencySet.scope=system to only include the system dependencies that are giving you trouble.
like image 190
Sander Verhagen Avatar answered Jan 29 '26 22:01

Sander Verhagen