参考 https://blog.csdn.net/lzxlfly/article/details/80710861
我将第一个akka程序打包成可执行的jar包,在命令行中通过java -jar unnamed.jar执行时出现:
D:\tmp\ideademos\out\artifacts\unnamed>java -jar unnamed.jarError: A JNI error has occurred, please check your installation and try againException in thread "main" java.lang.NoClassDefFoundError: akka/actor/ActorSystem 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: akka.actor.ActorSystem 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) ... 7 more
再 项目->open module setting->Modules->Dependencies 加上scala sdk的library及akka的相关库,再Build--Build Artifict--ReBuild
还是出现同样的错误。估计是因为我的idea中的global libraries设置的scala sdk是2.11,而我的系统scala用的是2.12(当时用2.12写akka时通过idea安装了com_typesafe_akka_akka_actor_2_12_0_M1_2_4_M2库,这个库不能在2.12 scala中使用,只能在2.11中使用),所以在IDEA中运行例子时很正常,但在cmd命令行中运行时就不正常了。