Can't deploy Scala Hello World

1,548 views
Skip to first unread message

Rich Oliver

unread,
May 28, 2013, 5:43:59 PM5/28/13
to scala-i...@googlegroups.com
I have a java file:

public class MainJava {
    public static void main(String[] args)    {
        System.out.println("Hello, World");
        MainScala.f1();
   }
}

and a Scala file:

object MainScala {
   def f1 = println("Scala")
}

Compiles and runs in Eclipse as expected. If I comment out the MainScala.f1(); I can export the programme as a runnable jar and then run it:

ro@dhcppc4:~/workspace> java -jar hrun.jar

but if the Scala method is not commented out then when I run it from the command  line I get:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$
        at MainScala$.f1(MainScala.scala:3)
        at MainScala.f1(MainScala.scala)
        at MainJava.main(MainJava.java:7)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 3 more

I have included the Scala Library and ticked its check box on the Java build path. I'm using Eclipse 4.2.2, Scala plug-in 3.0, Scala 2.10.1 in Linux Opensuse 12.3



Simon Schäfer

unread,
May 28, 2013, 5:54:28 PM5/28/13
to scala-i...@googlegroups.com
It looks like the Scala library is not correctly linked. What is the
content of the JAR and what does the Manifest of the JAR contain?
> --
> You received this message because you are subscribed to the Google
> Groups "Scala IDE User" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scala-ide-use...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Rich Oliver

unread,
May 28, 2013, 6:05:58 PM5/28/13
to scala-i...@googlegroups.com
Ah I should have looked it doesn't seem to be including Scala Library Classes

there's just the one file for the java and 2 others ScalaMain$ and ScalaMain. Manifest as follows:

Manifest-Version: 1.0
Class-Path: .
Main-Class: MainJava

Rich Oliver

unread,
May 28, 2013, 8:18:45 PM5/28/13
to scala-i...@googlegroups.com
I've got it to work manually by adding the Scala Directory from the Scala Library jar from sbt to the runnable jar. But I can't workout how why Eclipse is not adding the Scala Library.
Reply all
Reply to author
Forward
0 new messages