Java 在命令行上运行Apache Ignite时无法创建Ignite组件
在开始学习ignite时,我最终使用IntelliJ作为IDE,它一直工作良好。然而,我需要把它转移到一个超级计算机环境中,并且需要能够从命令行运行它,但是我的代码无法找到所需的类。我使用maven创建了我的项目,并添加了《入门指南》中提到的适当的依赖项。接下来,我让maven打包该项目,并使用以下命令:Java 在命令行上运行Apache Ignite时无法创建Ignite组件,java,maven,ignite,Java,Maven,Ignite,在开始学习ignite时,我最终使用IntelliJ作为IDE,它一直工作良好。然而,我需要把它转移到一个超级计算机环境中,并且需要能够从命令行运行它,但是我的代码无法找到所需的类。我使用maven创建了我的项目,并添加了《入门指南》中提到的适当的依赖项。接下来,我让maven打包该项目,并使用以下命令: /usr/java/jdk1.8.0_91/bin/java -cp "${IGNITE_HOME}/modules/core/target/ignite-core-1.6.0.jar:${I
/usr/java/jdk1.8.0_91/bin/java -cp "${IGNITE_HOME}/modules/core/target/ignite-core-1.6.0.jar:${IGNITE_HOME}/modules/core/target/libs/cache-api-1.0.0.jar:${IGNITE_HOME}/modules/spring/target/ignite-spring-1.6.0.jar:target/my-app-1.0-SNAPSHOT.jar" com.mycompany.app.App
但是,由于以下错误,无法创建点火组件:
Exception in thread "main" class org.apache.ignite.IgniteException: Failed to create Ignite component (consider adding ignite-spring module to classpath) [component=SPRING, cls=org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl]
at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:906)
at org.apache.ignite.Ignition.start(Ignition.java:350)
at com.mycompany.app.App.main(App.java:24)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to create Ignite component (consider adding ignite-spring module to classpath) [component=SPRING, cls=org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl]
at org.apache.ignite.internal.IgniteComponentType.componentException(IgniteComponentType.java:313)
at org.apache.ignite.internal.IgniteComponentType.create0(IgniteComponentType.java:289)
at org.apache.ignite.internal.IgniteComponentType.create(IgniteComponentType.java:200)
at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:637)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:840)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:749)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:619)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:589)
at org.apache.ignite.Ignition.start(Ignition.java:347)
... 1 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/BeansException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.ignite.internal.IgniteComponentType.create0(IgniteComponentType.java:275)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.BeansException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more
寻找其他类似的问题,我发现这是因为pom文件中没有包含ignite spring。然而,我已经包括了这一点。这是我的pom文件:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
</project>
4.0.0
com.mycompany.app
我的应用程序
罐子
1.0-快照
我的应用程序
http://maven.apache.org
org.apache.maven.plugins
maven编译器插件
3.5.1
1.8
1.8
org.apache.ignite
点火芯
1.6.0
org.apache.ignite
点火弹簧
1.6.0
org.apache.ignite
点燃索引
1.6.0
我哪里做错了?IDE中的重要信息是否导致某些内容变得不一致?我运行代码的命令是否不完整或错误?谢谢你的帮助。如果需要,这里是发生错误的代码的第一行:
package com.mycompany.app;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.StringTokenizer;
public class App
{
public static void main( String[] args ) {
printClasspath();
String data;
try {
data = readFile("tweet.txt");
Ignite ignite = Ignition.start("/ignite-1.6.0/examples/config/example-ignite.xml");
IgniteCache<Integer, String[]> cache = ignite.getOrCreateCache("myCacheName");
...
}
}
}
package com.mycompany.app;
导入org.apache.ignite.ignite;
导入org.apache.ignite.IgniteCache;
导入org.apache.ignite.Ignition;
导入java.io.BufferedReader;
导入java.io.FileReader;
导入java.io.IOException;
导入java.net.URL;
导入java.net.URLClassLoader;
导入java.util.StringTokenizer;
公共类应用程序
{
公共静态void main(字符串[]args){
printClasspath();
字符串数据;
试一试{
data=readFile(“tweet.txt”);
Ignite Ignite=Ignition.start(“/Ignite-1.6.0/examples/config/example Ignite.xml”);
IgniteCache cache=ignite.getOrCreateCache(“myCacheName”);
...
}
}
}
我建议执行以下操作:
Ignite_HOME/libs
文件夹中MAIN\u CLASS
环境变量设置为您的主类(com.mycompany.app.app
)IGNITE\u HOME/bin/IGNITE.sh
脚本。它将使用所有必需的Ignite依赖项正确地形成Java的classpath参数,并将运行您的应用程序因为类不是由java类标识的 请参阅以下命令 UNIX上的安装
//program starting#################################################################################################################################
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.IgniteCache;
//import org.apache.ignite.internal.util.spring;
public class HelloWorld {
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/examples/config/example-ignite.xml")) {
// Put values in cache.
IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache");
cache.put(1, "Hello");
cache.put(2, "World");
cache.put(3,"Durga Prasad");
// Get values from cache
// Broadcast 'Hello World' on all the nodes in the cluster.
ignite.compute().broadcast(()->System.out.println(cache.get(1) + " " + cache.get(2) + " " +cache.get(3)));
}
}
}
//end program ######################################################################################################################
[stp@ril-srv-sp4 libs]$ java -cp "/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-core-1.5.0-b1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/cache-api-1.0.0.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-shmem-1.0.0.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/commons-codec-1.6.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/h2-1.3.175.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/ignite-indexing-1.5.0-b1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/lucene-core-3.5.0.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/commons-logging-1.1.1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-beans-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-expression-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/ignite-spring-1.5.0-b1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-context-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-jdbc-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-aop-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-core-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-tx-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/HelloWorld.jar" HelloWorld
[14:14:26] __________ ________________
[14:14:26] / _/ ___/ |/ / _/_ __/ __/
[14:14:26] _/ // (7 7 // / / / / _/
[14:14:26] /___/\___/_/|_/___/ /_/ /___/
[14:14:26]
[14:14:26] ver. 1.5.0-b1#20151202-sha1:062d440c
[14:14:26] 2015 Copyright(C) Apache Software Foundation
[14:14:26]
[14:14:26] Ignite documentation: http://ignite.apache.org
[14:14:26]
[14:14:26] Quiet mode.
[14:14:26] ^-- Logging to file '/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/work/log/ignite-6790e4dd.0.log'
[14:14:26] ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[14:14:26]
[14:14:26] OS: Linux 3.10.0-327.el7.x86_64 amd64
[14:14:26] VM information: OpenJDK Runtime Environment 1.8.0_102-b14 Oracle Corporation OpenJDK 64-Bit Server VM 25.102-b14
[14:14:26] Configured plugins:
[14:14:26] ^-- None
[14:14:26]
[14:14:26] Security status [authentication=off, tls/ssl=off]
[14:14:28] Performance suggestions for grid (fix if possible)
[14:14:28] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[14:14:28] ^-- Disable peer class loading (set 'peerClassLoadingEnabled' to false)
[14:14:28] ^-- Disable grid events (remove 'includeEventTypes' from configuration)
[14:14:28]
[14:14:28] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[14:14:28]
[14:14:28] Ignite node started OK (id=6790e4dd)
[14:14:28] Topology snapshot [ver=2, servers=2, clients=0, CPUs=4, heap=14.0GB]
Hello World Durga Prasad
[14:14:29] Ignite node stopped OK [uptime=00:00:00:633]
[stp@ril-srv-sp4 bin]$ ./ignite.sh "/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/examples/config/example-ignite.xml"
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[14:14:17] __________ ________________
[14:14:17] / _/ ___/ |/ / _/_ __/ __/
[14:14:17] _/ // (7 7 // / / / / _/
[14:14:17] /___/\___/_/|_/___/ /_/ /___/
[14:14:17]
[14:14:17] ver. 1.5.0-b1#20151202-sha1:062d440c
[14:14:17] 2015 Copyright(C) Apache Software Foundation
[14:14:17]
[14:14:17] Ignite documentation: http://ignite.apache.org
[14:14:17]
[14:14:17] Quiet mode.
[14:14:17] ^-- Logging to file '/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/work/log/ignite-825641bf.0.log'
[14:14:17] ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[14:14:17]
[14:14:17] OS: Linux 3.10.0-327.el7.x86_64 amd64
[14:14:17] VM information: OpenJDK Runtime Environment 1.8.0_102-b14 Oracle Corporation OpenJDK 64-Bit Server VM 25.102-b14
[14:14:17] Configured plugins:
[14:14:17] ^-- None
[14:14:17]
[14:14:17] Security status [authentication=off, tls/ssl=off]
[14:14:19] Performance suggestions for grid (fix if possible)
[14:14:19] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[14:14:19] ^-- Disable peer class loading (set 'peerClassLoadingEnabled' to false)
[14:14:19] ^-- Disable grid events (remove 'includeEventTypes' from configuration)
[14:14:19]
[14:14:19] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[14:14:19]
[14:14:19] Ignite node started OK (id=825641bf)
[14:14:19] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, heap=1.0GB]
[14:14:28] New version is available at ignite.apache.org: 1.7.0
[14:14:28] Topology snapshot [ver=2, servers=2, clients=0, CPUs=4, heap=14.0GB]
Hello World Durga Prasad
[14:14:29] Topology snapshot [ver=3, servers=1, clients=0, CPUs=4, heap=1.0GB]
感谢您的快速响应,我能够以这种方式工作。我想知道这是否是在ignite上运行应用程序的首选方式。这是唯一的办法吗?我这样问是因为在我们的设置中,我们不希望每个用户都将他们的JAR放入共享的IGNITE_HOME/libs。另外,如果多个服务器都试图运行主类,您将如何将它们连接在一起?我对管理系统没有太多的干扰,但是如果我尝试在未设置主类的情况下设置一些服务器,然后在设置主类的情况下运行一个,网格管理器会出错。您可以启动任意数量的独立服务器。上面显示的方法只是使用Ignite依赖项运行应用程序的方法之一(显然不是唯一的方法)。
[stp@ril-srv-sp4 libs]$ java -cp "/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-core-1.5.0-b1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/cache-api-1.0.0.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-shmem-1.0.0.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/commons-codec-1.6.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/h2-1.3.175.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/ignite-indexing-1.5.0-b1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-indexing/lucene-core-3.5.0.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/commons-logging-1.1.1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-beans-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-expression-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/ignite-spring-1.5.0-b1.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-context-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-jdbc-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-aop-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-core-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/ignite-spring/spring-tx-4.1.0.RELEASE.jar:/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/libs/HelloWorld.jar" HelloWorld
[14:14:26] __________ ________________
[14:14:26] / _/ ___/ |/ / _/_ __/ __/
[14:14:26] _/ // (7 7 // / / / / _/
[14:14:26] /___/\___/_/|_/___/ /_/ /___/
[14:14:26]
[14:14:26] ver. 1.5.0-b1#20151202-sha1:062d440c
[14:14:26] 2015 Copyright(C) Apache Software Foundation
[14:14:26]
[14:14:26] Ignite documentation: http://ignite.apache.org
[14:14:26]
[14:14:26] Quiet mode.
[14:14:26] ^-- Logging to file '/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/work/log/ignite-6790e4dd.0.log'
[14:14:26] ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[14:14:26]
[14:14:26] OS: Linux 3.10.0-327.el7.x86_64 amd64
[14:14:26] VM information: OpenJDK Runtime Environment 1.8.0_102-b14 Oracle Corporation OpenJDK 64-Bit Server VM 25.102-b14
[14:14:26] Configured plugins:
[14:14:26] ^-- None
[14:14:26]
[14:14:26] Security status [authentication=off, tls/ssl=off]
[14:14:28] Performance suggestions for grid (fix if possible)
[14:14:28] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[14:14:28] ^-- Disable peer class loading (set 'peerClassLoadingEnabled' to false)
[14:14:28] ^-- Disable grid events (remove 'includeEventTypes' from configuration)
[14:14:28]
[14:14:28] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[14:14:28]
[14:14:28] Ignite node started OK (id=6790e4dd)
[14:14:28] Topology snapshot [ver=2, servers=2, clients=0, CPUs=4, heap=14.0GB]
Hello World Durga Prasad
[14:14:29] Ignite node stopped OK [uptime=00:00:00:633]
[stp@ril-srv-sp4 bin]$ ./ignite.sh "/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/examples/config/example-ignite.xml"
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[14:14:17] __________ ________________
[14:14:17] / _/ ___/ |/ / _/_ __/ __/
[14:14:17] _/ // (7 7 // / / / / _/
[14:14:17] /___/\___/_/|_/___/ /_/ /___/
[14:14:17]
[14:14:17] ver. 1.5.0-b1#20151202-sha1:062d440c
[14:14:17] 2015 Copyright(C) Apache Software Foundation
[14:14:17]
[14:14:17] Ignite documentation: http://ignite.apache.org
[14:14:17]
[14:14:17] Quiet mode.
[14:14:17] ^-- Logging to file '/home/stp/ignite/apache-ignite-fabric-1.5.0-b1-bin/work/log/ignite-825641bf.0.log'
[14:14:17] ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[14:14:17]
[14:14:17] OS: Linux 3.10.0-327.el7.x86_64 amd64
[14:14:17] VM information: OpenJDK Runtime Environment 1.8.0_102-b14 Oracle Corporation OpenJDK 64-Bit Server VM 25.102-b14
[14:14:17] Configured plugins:
[14:14:17] ^-- None
[14:14:17]
[14:14:17] Security status [authentication=off, tls/ssl=off]
[14:14:19] Performance suggestions for grid (fix if possible)
[14:14:19] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[14:14:19] ^-- Disable peer class loading (set 'peerClassLoadingEnabled' to false)
[14:14:19] ^-- Disable grid events (remove 'includeEventTypes' from configuration)
[14:14:19]
[14:14:19] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[14:14:19]
[14:14:19] Ignite node started OK (id=825641bf)
[14:14:19] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, heap=1.0GB]
[14:14:28] New version is available at ignite.apache.org: 1.7.0
[14:14:28] Topology snapshot [ver=2, servers=2, clients=0, CPUs=4, heap=14.0GB]
Hello World Durga Prasad
[14:14:29] Topology snapshot [ver=3, servers=1, clients=0, CPUs=4, heap=1.0GB]