如何在jvm上运行scala字节码? [英] How do run scala bytecode on the jvm?
问题描述
如何在jvm上运行已编译的scala代码?
当我尝试以下命令时:
java -cp scala-library.jar -cp bin com.mcmc5.Main
我收到以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: main
在scala代码中,我有一个名为Main的对象,并且在其中定义了main函数.如果我做的话就行了
scala -cp bin com.mcmc5.Main
,它工作正常.
有什么我想念的吗?
谢谢你, thejinx0r
这是我的代码:
我希望它在JVM上运行的原因是因为我要实际执行字节码的服务器未安装scala.这是我的主要工具的本质(它具有一些在其之前定义的值和变量,但本质上是:
但是我仍然尝试使用
java -cp scala-library.jar:bin com.mcmc5.Main
,我仍然遇到相同的错误.
编辑2 问题解决了.
所以我实际上不相信这一点,但这对我有用.
所以我找到了线程
(如果可以这样称呼),并说Java通常不喜欢整个 object Main extends Application
但是,这实际上解决了我的问题.通过使用extends Application
而不是定义一个名为main的函数,解决了我的问题.我猜这取决于您所使用的scala版本.我目前使用的是Scala 2.9,也许是rc2?还是rc1?
在Windows上,
java -cp scala-library.jar;bin com.mcmc5.Main
或其他地方
java -cp scala-library.jar:bin com.mcmc5.Main
只有一个组合的"-cp"选项.鉴于com.mcmc5.Main是使用scalac
编译的,这绝对是正确的方法.
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 works 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
.
这篇关于如何在jvm上运行scala字节码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!