Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:24:47+00:00 2026-05-16T02:24:47+00:00

Let’s say I have this Hello.scala. object HelloWorld { def main(args: Array[String]) { println(Hello,

  • 0

Let’s say I have this Hello.scala.

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

I could run ‘scalac’ to get HelloWorld.class and HelloWorld$.class.
I can run using ‘scala -classpath . Hello’. But I can’t run ‘java -cp . Hello’.

  • Why is this? Isn’t scala interoperable with Java?
  • Is there any way to run scala’s class with Java?
  • Why the scalac produces two class files?
  • Does scala have something like ‘lein uber’? I mean, does scala have some tools that generates one jar file for distribution purposes?

IntelliJ + scala plugin

I could get a jar that contains everything to run scala file file with IntelliJ + scala plugin, I think this is the better option than proguard.

proguard setup

Thanks to Moritz, I could make one jar file that be run with java.
This is the overall structure.

|-- classes
|   |-- HelloWorld$.class
|   |-- HelloWorld.class
|   `-- META-INF
|       `-- MANIFEST.MF
`-- your.pro

your.pro has the following contents.

-injar classes
-injar /Users/smcho/bin/scala/lib/scala-library.jar(!META-INF/MANIFEST.MF)
-outjar main.jar
-libraryjar /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar

-dontwarn
-dontnote
-ignorewarnings

-optimizationpasses 2
-optimizations !code/allocation/variable

-keep,allowoptimization,allowshrinking class * { *; }
-keepattributes SourceFile,LineNumberTable

-keepclasseswithmembers public class HelloWorld { public static void main(java.lang.String[]); }

MANIFEST.MF has following setup. Don’t forget to include [CR] or blank line.

Main-Class: HelloWorld

I download the proguard 4.5.1 to put it in ~/bin/proguard4.5.1.
Running proguard, I could make the jar (main.jar), and it works fine.

prosseek:classes smcho$ java -Xmx512m -jar /Users/smcho/bin/proguard4.5.1/lib/proguard.jar @your.pro

ProGuard, version 4.5.1
Reading program directory [/Users/smcho/Desktop/scala/proguard/classes/classes]
Reading program jar [/Users/smcho/bin/scala/lib/scala-library.jar] (filtered)
Reading library jar [/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar]
Preparing output jar [/Users/smcho/Desktop/scala/proguard/classes/main.jar]
  Copying resources from program directory [/Users/smcho/Desktop/scala/proguard/classes/classes]
  Copying resources from program jar [/Users/smcho/bin/scala/lib/scala-library.jar] (filtered)
prosseek:classes smcho$ java -jar main.jar hello

or

java -cp main.jar HelloWorld

I upload the example zip file here. And, scalar source code here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:24:48+00:00Added an answer on May 16, 2026 at 2:24 am

    You need to add Scala to the classpath, e.g.

    -classpath scala-library.jar:.
    

    or by adding

    -Xbootclasspath/a:scala-library.jar
    

    to the VM arguments.

    Addition:

    Sorry, did not see that last question. If you want do distribute single JAR files many people use ProGuard to ship the classes needed from the scala-library.jar along with your classes in one jar.

    Second Edit:

    Assuming you have your .class-files and your META-INF folder containing the MANIFEST.MF in a folder called classes you can use the following Proguard configuration (after adjusting the paths, e.g. you need rt.jar on Linux/Windows instead of classes.jar on Mac OS) saved e.g. as your.pro:

    -injar classes
    -injar /opt/local/share/scala-2.8/lib/scala-library.jar(!META-INF/MANIFEST.MF)
    -outjar main.jar
    -libraryjar /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar
    
    -dontwarn
    -dontnote
    -ignorewarnings
    
    -optimizationpasses 2
    -optimizations !code/allocation/variable
    
    -keep,allowoptimization,allowshrinking class * { *; }
    -keepattributes SourceFile,LineNumberTable
    
    -keepclasseswithmembers public class your.Main { public static void main(java.lang.String[]); }
    

    Now you can create main.jar with

    java -Xmx512m -jar proguard.jar @your.pro
    

    Eventually you have to set the -Xmx a bit higher. Some more info can be found on the SBT Wiki.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have the following classes : public class MyProductCode { private String
Let's say I have table with column 'URL' whrere I store urls like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.