Intellij Apache Ignite Project无法生成有效的JAR文件

时间:2018-12-04 15:26:44

标签: java spring maven intellij-idea ignite

我的Intellij项目在IDE内完美运行,但是任何试图从其中提取有效.jar文件的方法都会导致某种错误。 我的项目使用Maven,Spring和Apache Ignite。 这是我的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">
    <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>

清单:

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

然后,文件夹结构:

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

我在下面列出了尝试:

1-在mvn clean install目录中运行pom.xml:编译正常,但是相对于我的jar文件,我得到了错误no main manifest attribute

2-我打开了jar文件,并且清单明显不同:

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

所以我在这行后面加上了:

Main-Class: server.ServerNodeExample

现在我发现自己陷入了这个奇怪的异常之中:

  :$ 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

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

如果您希望能够使用java -jar运行项目,则需要构建fat jar。只要有依赖项,就不依赖于依赖项的性质。

您还可以尝试使用Spring Boot,它将为您做一个胖子。

我不建议使用Apache Ignite 2.1,因为它已经很老了,当您知道如何启动项目时,Apache Ignite 2.7应该已经淘汰了。