简体   繁体   中英

Intellij Apache Ignite Project won't generate a working JAR File

My Intellij project is running flawlessly inside the IDE but any methods that attempted to extract a valid .jar file from it resulted in some kind of error. My project uses Maven, Spring and Apache Ignite. Here's my pom.xml 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">
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.1.RELEASE</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-gettings-started</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>javax.cache</groupId>
            <artifactId>cache-api</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-core</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-spring</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-indexing</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
        </dependency>



    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

</project>

The manifest:

Manifest-Version: 1.0
Main-Class: server.ServerNodeExample

And, the folder structure:

- project
  - .idea
  - out
  - src
    - main
      - java
        - examples
          - ...
        - server
          - ...
      - resources
        - META-INF
          - MANIFEST.MF
    - test
  - target
  - pom.xml

I list the attempts below:

1 - Running mvn clean install in the pom.xml directory: compiled fine, but I get the error no main manifest attribute relative to my jar file.

2 - I opened the jar file and the manifest there was quite different:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: evandro.teixeira
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_191

So i appended this line to it:

Main-Class: server.ServerNodeExample

And now I find myself stuck in this weird exception:

  :$ java -jar ignite-gettings-started-1.0.0.jar 
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ignite/IgniteException
  at java.lang.Class.getDeclaredMethods0(Native Method)
  at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
  at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
  at java.lang.Class.getMethod0(Class.java:3018)
  at java.lang.Class.getMethod(Class.java:1784)
  at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.ignite.IgniteException
  at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 7 more

Any ideas?

You will need to build a fat jar if you want to be able to run your project with java -jar . This does not depend on the nature of your dependencies as long as you have any of them.

You could also try and use Spring Boot which will do a fat jar for you.

And I do not recommend using Apache Ignite 2.1 since it's very old and Apache Ignite 2.7 should be already out when you figure out how to launch your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM