參考 https://blog.csdn.net/lzxlfly/article/details/80710861java
我將第一個akka程序打包成可執行的jar包,在命令行中經過java -jar unnamed.jar執行時出現:ide
D:\tmp\ideademos\out\artifacts\unnamed>java -jar unnamed.jar Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: akka/actor/ActorSyste m 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--ReBuildui
仍是出現一樣的錯誤。估計是由於個人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命令行中運行時就不正常了。idea