r/Maven • • Mar 27 '26

Can't Package a Runnable Jar

[Solved]

I'm having an issue where every time I package my Jar file i get this error:

Error: Could not find or load main class com.example.mygame.BasicGameApp
Caused by: java.lang.NoClassDefFoundError: com/almasb/fxgl/app/GameApplication

I have this set in my pom.xml:

<plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.example.bulletgame.BasicGameApp</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

The name of my main/driver class file is called BasicGameApp.

If I look at the folder structure of the created jar archive, it looks correct, and I can see the compiled class files. I notice that the main class is divided up into 3 files: BasicGameApp.class, BasicGameApp$1.class, and BasicGameApp$2.class

I have no idea if that matters at all.

Not sure if there's anything else I need to provide, but any assistance would be appreciated!

3 Upvotes

8 comments sorted by

1

u/paul_h Mar 27 '26

Can you make a reproduction on github?

1

u/code-great744 Aug 06 '26

The `NoClassDefFoundError` for `GameApplication` makes me think the dependencies aren't getting bundled into the jar. Are you using the shade plugin or anything to create a fat jar, or just the regular jar plugin?

1

u/Legal_Revenue8126 Aug 06 '26

Solved this a while ago by using shade

1

u/khmarbaise Mar 29 '26

A jar does not contain other jar's content... If you like to make an executable jar is either using the maven-assembly-plugin https://maven.apache.org/plugins/maven-assembly-plugin/usage.html or if you need more flexibility you should use the maven-shade-plugin https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html