我有一些问题的java。一探究竟。
sebastian @ sebastian-desktop:〜/ scaaaaaaaaala $ java -cp /home/sebastian/.m2/repository/org/scala-lang/scala-library/2.8.0.RC3/scala-library-2.8.0.RC3.jar :target / scaaaaaaaaala-1.0.jar scaaalaaa.App
Hello World!
这很酷,对,但是怎么回事这:
sebastian @ sebastian-desktop:〜/ scaaaaaaaaala $ java -cp /home/sebastian/.m2/repository/org/scala-lang/scala-library/2.8.0.RC3/scala-library-2.8.0.RC3.jar -jar target / scaaaaaaaaala-1.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Application at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at scaaalaaa.App.main(App.scala) Caused by: java.lang.ClassNotFoundException: scala.Application at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 13 more
Wat the heck?任何想法为什么第一个工作,而不是第二?我怎么样 – 我的scala?
我先感谢,兄弟。
解决方法
如果您定义-jar,则忽略-classpath:
-jar When you use this option,the JAR file is the source of all user
classes,and other user class path
settings are ignored.
您可以在Manifest metadata中定义类路径依赖关系。
启动应用程序的最简单方法是使用scala脚本:
scala -classpath target/scaaaaaaaaala-1.0.jar scaaalaaa.App Hello World!