开发者

How do run scala bytecode on the jvm?

开发者 https://www.devze.com 2023-02-28 18:34 出处:网络
How do I run the compiled scala code on jvm? When I try the following command: java -cp scala-library.jar -cp bin com.mcmc5.Main

How do I run the compiled scala code on jvm?

When I try the following command:

java -cp scala-library.jar -cp bin com.mcmc5.Main

I get the following error: Exception in thread "main" java.lang.NoSuchMethodError: main

In the scala code, I have an object called Main and it has the main function defined in there. It works if I do scala -cp bin com.mcmc5.Main , it 开发者_如何学JAVAworks fine.

Is there something that I am missing?

Thank you, thejinx0r

Edit1: Here's my code: The reason why I want it to run on the JVM is because the server where I want to actually execute the bytecode does not have scala installed. This is what my main has essentially (it has some values and variables defined before it, but essentially:

package com.mcmc5
import java.text.{DateFormat, NumberFormat, DecimalFormat, SimpleDateFormat}
import java.util.{Date}
 object Main {  def main( args: Array[String]) = {
        println(numberOfOutputStructures)
        var structureSolver = new MC(20);
        structureSolver.start()
    }
} 

But I still tried using java -cp scala-library.jar:bin com.mcmc5.Main and I still got the same error.

Edit 2 Problem solved.

So I actually don't believe this, but this works for me.

So I had found a thread ( if you can call it that ) and said that java usually does not like the whole object Main extends Application But, that actually solved my problem. By using extends Application instead of defining a function called main solved my problem. I guess it depends on what version of scala you are using. I'm currently on scala 2.9, rc2 perhaps? or rc1?


On Windows,

java -cp scala-library.jar;bin com.mcmc5.Main

or elsewhere

java -cp scala-library.jar:bin com.mcmc5.Main

Just a single combined "-cp" option. This is definitely the correct way, given that com.mcmc5.Main was compiled with scalac.

0

精彩评论

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