'Maven - jar built using the jar plugin shows an error message when trying to run it

I get two separate error windows when trying to run the created jar:

"Error: A JNI error has occurred, please check your installation and try again."

Followed by:

(Java Virtual Machine Launcher)
"A Java Exception has occurred."

My project itself runs just fine, and the jdk, jre are both of version "17". The jar command in maven is use is the default: jar:jar -f pom.xml. I tried running jar -t ThesisMVN-1.0-SNAPSHOT.jar which hang and didn't produce a result after 10s, as well as jar --validate ThesisMVN-1.0-SNAPSHOT.jar, which gave me the following errors:

java.nio.file.FileAlreadyExistsException: C:\Users\user\AppData\Local\Temp\tmpJar404095564019557515.jar
        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:87)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:236)
        at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:484)
        at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
        at java.base/java.nio.file.Files.copy(Files.java:3160)
        at jdk.jartool/sun.tools.jar.Main.run(Main.java:411)
        at jdk.jartool/sun.tools.jar.Main.main(Main.java:1665)

Finally, this is what my pom.xml looks like:

<?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>hu.elte.inf</groupId>
    <artifactId>ThesisMVN</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>main/Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.javatuples</groupId>
            <artifactId>javatuples</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
</project>

(No clue what the final tag and its contents are for but removing it didn't affect the result of my problem).

What am I missing here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source