开发者

Running a Scala app as a Java app

开发者 https://www.devze.com 2023-01-12 03:18 出处:网络
I\'m trying to run the following rocket launching application: object HelloWorld { def main(args: Array[String]) {

I'm trying to run the following rocket launching application:

object HelloWorld {
    def main(args: Array[String]) {
        println("Hello World!")
    }
}

directly from java like this:

java -cp scala-library.jar HelloWorld

(obviously after compliling with scala)

but get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
        at java.net.URLClassLoader$1.run(Unknown Source)
(...)
Could not find the main class: HelloWorld.  Program will exit.

H开发者_开发百科ave I overseen anything trivial that I need to do to make it work?


From the Java documentation:

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

Adding .: (or .; on Windows) to the beginning of your classpath should work.


Please try:

java -cp %SCALA_HOME%\lib\scala-library.jar;. HelloWorld

0

精彩评论

暂无评论...
验证码 换一张
取 消