Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do run scala bytecode on the jvm?

Tags:

java

jvm

scala

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?

like image 732
thejinx0r Avatar asked Apr 27 '11 01:04

thejinx0r


1 Answers

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.

like image 187
Ernest Friedman-Hill Avatar answered Oct 03 '22 06:10

Ernest Friedman-Hill