You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by w f <wm...@yahoo.com.INVALID> on 2025/04/01 10:50:24 UTC

How to include a custom library jar in the final jar

I'm working on an application suite which consists of three (3) Maven projects:
* tm-server
* tm-client
* tm-toolib

Current 3rd-party dependencies for tm-server and tm-client are an MQTT library and a database library.
Both tm-server and tm-client are dependent on my tm-toolib. tm-toolib has no dependencies.

I have my pom configured such that all dependent jars are rolled into one final jar.
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.7.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <archive>
            <manifest>
              <mainClass>
                org.pynkon.tm.client.App
              </mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </execution>
    </executions>
  </plugin>

This works for the 3rd-party jars but not my tm-toolib jar.

My dependencies configured like this:
  <dependencies>
    <dependency>
      <groupId>org.xerial</groupId>
      <artifactId>sqlite-jdbc</artifactId>
      <version>3.49.1.0</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.paho</groupId>
      <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
      <version>1.2.5</version>
    </dependency>
    <dependency>
      <groupId>org.pynkon.tm.toolib</groupId>
      <artifactId>tm-toolib</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/../tm-toolib/target/tm-toolib-1.0-SNAPSHOT.jar</systemPath>
    </dependency>
  <dependencies>
(I get warnings about my tm-toolib but only warnings.)

All three projects compile, but when I execute tm-client, I get a ClassNotFoundException
as soon as the application uses something from tm-toolib

It's almost as if the above stanza for tm-toolib is acting as a compile-time stub;
dependencies are resolved at build time but never included for use at runtime.

I know I'm doing something wrong; I just don't know what it is.

Are MQTT and Xerial rolled up in the final jar bc. they're coming from a repository?
Do I have to use "mvn install:install-file ..." on my tm-toolib jar to add it to
my local repository?
If so, do I have to re-add it each time it's modified?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to include a custom library jar in the final jar

Posted by Hans Aikema <ha...@aikebah.net.INVALID>.

> Op 1 apr 2025 om 13:07 heeft Mantas Gridinas <mg...@gmail.com> het volgende geschreven:
> 
> If the other dependency is also managed by maven, you can build it with
> install goal, and it will end up in your local repository and you won't
> need to readd it every time. Looking at jar-with-dependencies assembly
> definition it only includes runtime dependencies, and this imposes a
> question - are system dependencies considered available at runtime?
> https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies
> 
> 
>> On Tue, Apr 1, 2025, 13:52 w f <wm...@yahoo.com.invalid> wrote:
>> 
>> 
>> My dependencies configured like this:
>>   
>>    <dependency>
>>      <groupId>org.pynkon.tm.toolib</groupId>
>>      <artifactId>tm-toolib</artifactId>
>>      <version>1.0</version>
>>      <scope>system</scope>
>> 
>> <systemPath>${project.basedir}/../tm-toolib/target/tm-toolib-1.0-SNAPSHOT.jar</systemPath>
>>    </dependency>
>>  <dependencies>
>> (I get warnings about my tm-toolib but only warnings.)

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies

Putting your own projects is not what the (already deprecated) system scope is meant for.
You should mvn install (or deploy) them if it's not a multimodule project. If you build as a multi-module project simply put the dependency in and all will work just fine, even with only mvn package (it will resolve the jar from target because it's part of the same multimodule built and will know to first build tm-toollib before the other two due to the internal dependencies)


Re: How to include a custom library jar in the final jar

Posted by Mantas Gridinas <mg...@gmail.com>.
If the other dependency is also managed by maven, you can build it with
install goal, and it will end up in your local repository and you won't
need to readd it every time. Looking at jar-with-dependencies assembly
definition it only includes runtime dependencies, and this imposes a
question - are system dependencies considered available at runtime?
https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies


On Tue, Apr 1, 2025, 13:52 w f <wm...@yahoo.com.invalid> wrote:

> I'm working on an application suite which consists of three (3) Maven
> projects:
> * tm-server
> * tm-client
> * tm-toolib
>
> Current 3rd-party dependencies for tm-server and tm-client are an MQTT
> library and a database library.
> Both tm-server and tm-client are dependent on my tm-toolib. tm-toolib has
> no dependencies.
>
> I have my pom configured such that all dependent jars are rolled into one
> final jar.
>   <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-assembly-plugin</artifactId>
>     <version>3.7.1</version>
>     <executions>
>       <execution>
>         <phase>package</phase>
>         <goals>
>           <goal>single</goal>
>         </goals>
>         <configuration>
>           <archive>
>             <manifest>
>               <mainClass>
>                 org.pynkon.tm.client.App
>               </mainClass>
>             </manifest>
>           </archive>
>           <descriptorRefs>
>             <descriptorRef>jar-with-dependencies</descriptorRef>
>           </descriptorRefs>
>         </configuration>
>       </execution>
>     </executions>
>   </plugin>
>
> This works for the 3rd-party jars but not my tm-toolib jar.
>
> My dependencies configured like this:
>   <dependencies>
>     <dependency>
>       <groupId>org.xerial</groupId>
>       <artifactId>sqlite-jdbc</artifactId>
>       <version>3.49.1.0</version>
>     </dependency>
>     <dependency>
>       <groupId>org.eclipse.paho</groupId>
>       <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
>       <version>1.2.5</version>
>     </dependency>
>     <dependency>
>       <groupId>org.pynkon.tm.toolib</groupId>
>       <artifactId>tm-toolib</artifactId>
>       <version>1.0</version>
>       <scope>system</scope>
>
> <systemPath>${project.basedir}/../tm-toolib/target/tm-toolib-1.0-SNAPSHOT.jar</systemPath>
>     </dependency>
>   <dependencies>
> (I get warnings about my tm-toolib but only warnings.)
>
> All three projects compile, but when I execute tm-client, I get a
> ClassNotFoundException
> as soon as the application uses something from tm-toolib
>
> It's almost as if the above stanza for tm-toolib is acting as a
> compile-time stub;
> dependencies are resolved at build time but never included for use at
> runtime.
>
> I know I'm doing something wrong; I just don't know what it is.
>
> Are MQTT and Xerial rolled up in the final jar bc. they're coming from a
> repository?
> Do I have to use "mvn install:install-file ..." on my tm-toolib jar to add
> it to
> my local repository?
> If so, do I have to re-add it each time it's modified?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: How to include a custom library jar in the final jar

Posted by Bernd Eckenfels <ec...@zusammenkunft.net>.
Hello,

the reason why it is not picked up as a dependency is, because it  is a system scope, which means “provided” by the system. If you change that to default scope, it will be considered.

You don’t need to specify the relative path, you either build the parent reactor, then the neighbour modules are automatically available or you once install the dependent module, then it also resolves normally. (Also not specifying the version).

Technically I think some plugins allow to change the scopes they consider, but like with everything else in Maven land, don’t stray from the path, you just hurt yourself down the line.

Gruss
Bernd 

w f wrote on 1. Apr 2025 12:50 (GMT +02:00):

>  <scope>system</scope>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org