Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: maven package one final jar including local jar

  1. #1
    Junior Member
    Join Date
    Oct 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default maven package one final jar including local jar

    I have been working on my first sharp project for the last month and I am a newbie on java. Everything has worked out fine running the application in vs code using maven and some external dependencies and I have also referenced a local api.jar file as a maven dependency. Now I am at the stage where I am about to package the application and I want to create a jar file that includes my whole project and all dependencies. I now spent a whole day trying to find a solution to this and it seems ridiculously complicated comparing to more modern languages.

    I have finally landed in using the maven-assembly plugin (not sure if this is the best choice) but after hours of googeling this seemed to be the best choice to achieve this.

    Pressing the "package" button in vs code renders a jar-with-dependencies.jar with success but when running it with "java -jar nameojar.jar it can not find
    classes from local dependency api.jar (even though the project runs inside vs code) "main" java.lang.NoClassDefFoundError: pico/db/DBException

    I previously had other local jars that gave the same error type but changing to normal remote dependencies solved it and I am pretty sure the error comes from the last local jar not being included in the final jar. The only local jar that is left is unfortunately is an api that only exits as jar and not as a remote maven dep.

    How can I get this jar into my final jar?

    (changed names here for customer privacy so dont mind name typos if any)

    ____ POM FILE___
    <?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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
     
        <groupId>se.ax</groupId>
        <artifactId>ax</artifactId>
        <version>1.0</version>
     
        <repositories>
            <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
            </repository>
        </repositories>
     
       <properties>
            <maven.compiler.source>21</maven.compiler.source>
            <maven.compiler.target>21</maven.compiler.target>
     
            <vapipath>/home/mikael/.m2/repository/vapi/ax/5.0.4/ax-5.0.4.jar</vapiapath>
            <tinylogapipath>/home/mikael/.m2/repository/tinylogapi/ax/2.7.0/ax-2.7.0.jar</tinylogapipath> -->
     
        </properties> 
     
        <dependencies>
     
            <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>9.0.0</version>
            </dependency>
     
            <dependency>
                <groupId>com.github.Carleslc.Simple-YAML</groupId>
                <artifactId>Simple-Yaml</artifactId>
                <version>1.8.4</version>
            </dependency>
     
            <dependency>
            <groupId>org.tinylog</groupId>
            <artifactId>tinylog-api</artifactId>
            <version>2.7.0</version>
            </dependency>
     
            <dependency>
                <groupId>org.tinylog</groupId>
                <artifactId>tinylog-impl</artifactId>
                <version>2.7.0</version>
            </dependency> 
     
     
             <dependency>
                <groupId>vakaapi</groupId>
                <artifactId>ax</artifactId>
                <version>0.0.0</version>
                <scope>system</scope>
                <systemPath>${vakaapipath}</systemPath>
            </dependency>
     
     
     
        </dependencies>
     
        <build>
            <plugins>
     
     
     
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>ax.Main</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
     
                    </configuration>
                    <executions>
                        <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                        </execution>
                    </executions>
                    </plugin>
     
            </plugins>
        </build>
     
     
     
    </project>
    Thanks

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: maven package one final jar including local jar

    Sorry, I don't know of anyone on this forum that knows maven. Try asking this question on this site:
    http://www.coderanch.com/forums
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. In Java, are only local variables actually final
    By codingkeera in forum Java Theory & Questions
    Replies: 2
    Last Post: November 12th, 2023, 09:43 PM
  2. how to import/ access classes created in one package in another package
    By ydandurkar in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 11th, 2014, 11:12 AM
  3. Replies: 2
    Last Post: December 14th, 2012, 05:31 AM
  4. Simple package problem, package does not exist error
    By Farmer in forum Object Oriented Programming
    Replies: 3
    Last Post: August 23rd, 2011, 11:18 AM
  5. final class, final <variable> or <data member>
    By chronoz13 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 20th, 2009, 08:19 AM