3

In IntelliJ I'm using Maven to build a shaded jar of my project. I'm brand new to Maven and am probably doing something wrong despite my best efforts.

When I attempt to run the jar, I get the following error:

A JNI error has occurred, please check your installation and try again

I've checked my java version and it should be running off JDK14

>java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)

>javac -version
javac 14.0.1

I am not sure where I'm going wrong. Any help would be greatly appreciated. If you need any information that I haven't provided, please ask. As I'm new to Maven, I don't know what I should be sharing and what's pointless to share.

Additionally, would there be anyway to distribute this without each user having to upgrade to Java 11?

Here's my pom.xml

<?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>com.thenorsepantheon</groupId>
    <artifactId>wowslineupbuilder</artifactId>
    <name>WoWs Lineup Builder</name>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>28.2-jre</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.thenorsepantheon.wowslineupbuilder.WoWsLineupBuilder</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Spedwards
  • 4,167
  • 16
  • 49
  • 106

3 Answers3

0

I think you also have java8 or java9 installed on your Windows machine and you are running the jar by double-clicking on it. Windows is launching your jar with the older version of java. Please try running it from the command line to make sure it is launched by java14. Like

<jdk14-folder>\bin\java.exe -jar target\ -jar target\wowslineupbuilder-1.0-SNAPSHOT-shaded.jar

I would recommend you to uninstall the old java from your machine.

Regarding to your second question (distribution to users without jdk11 upgrade). You may have look at jlink which will allow you to create a custom JDK(small one) and distribute it with your jar.

Mehmet Sunkur
  • 2,373
  • 16
  • 22
0

This error possibly occurs if you have 2 versions of Java available in your system. When you try to run your application, it picks the different version and fail. I want you to first of all check your global system variables and JDK configured with intellij is same.

Then you have do ...

  • Right-click on the main method class, Click on "Run As", Click on "Java Application". The keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press X; then release Shift and Alt and press J).
Kunal Vohra
  • 2,703
  • 2
  • 15
  • 33
-1

This is basically your itellij error, intellij has it's own version of java sdk (Specially a new version) which might be a different version from your system installed version, to reslove this follow the follwing steps:-

1) You need to have a jdk installed on the system.

2) go to project structure under File menu ctrl+alt+shift+S

3) SDKs is located under Platform Settings. Select it.

4) click the green + up the top of the window.

5) select JDK (I have to use keyboard to select it do not know why).

select the home directory for your jdk installation.

should be good to go.

bforblack
  • 65
  • 5
  • Doesn't help me. I can run the project through IntelliJ just fine. It's the shaded jar that doesn't want to run. – Spedwards May 24 '20 at 16:03