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

  • SEARCH
  • Home
  • 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 206945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:41:30+00:00 2026-05-11T17:41:30+00:00

I’m new to Scala and don’t know Java. I want to create a jar

  • 0

I’m new to Scala and don’t know Java. I want to create a jar file out of a simple Scala file. So I have my HelloWorld.scala, generate a HelloWorld.jar.

Manifest.mf:

Main-Class: HelloWorld

In the console I run:

fsc HelloWorld.scala
jar -cvfm HelloWorld.jar Manifest.mf HelloWorld\$.class HelloWorld.class
java -jar HelloWorld.jar 
  => "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/jar"

java -cp HelloWorld.jar HelloWorld 
  => Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
    at hoppity.main(HelloWorld.scala)
  • 1 1 Answer
  • 1 View
  • 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-11T17:41:30+00:00Added an answer on May 11, 2026 at 5:41 pm

    Sample directory structure:

    X:\scala\bin
    X:\scala\build.bat
    X:\scala\MANIFEST.MF
    X:\scala\src
    X:\scala\src\foo
    X:\scala\src\foo\HelloWorld.scala
    

    HelloWorld.scala:

    //file: foo/HelloWorld.scala
    package foo {
      object HelloWorld {
        def main(args: Array[String]) {
          println("Hello, world!")
        }
      }
    }
    

    MANIFEST.MF:

    Main-Class: foo.HelloWorld
    Class-Path: scala-library.jar
    

    build.bat:

    @ECHO OFF
    
    IF EXIST hellow.jar DEL hellow.jar
    IF NOT EXIST scala-library.jar COPY %SCALA_HOME%\lib\scala-library.jar .
    
    CALL scalac -sourcepath src -d bin src\foo\HelloWorld.scala
    
    CD bin
    jar -cfm ..\hellow.jar ..\MANIFEST.MF *.*
    CD ..
    
    java -jar hellow.jar
    

    In order to successfully use the -jar switch, you need two entries in the META-INF/MANIFEST.MF file: the main class; relative URLs to any dependencies. The documentation notes:

    -jar

    Execute a program encapsulated in a
    JAR file. The first argument is the
    name of a JAR file instead of a
    startup class name. In order for this
    option to work, the manifest of the
    JAR file must contain a line of the
    form Main-Class: classname. Here,
    classname identifies the class having
    the public static void main(String[]
    args) method that serves as your
    application’s starting point. See the
    Jar tool reference page and the Jar
    trail of the Java Tutorial for
    information about working with Jar
    files and Jar-file manifests.

    When you use this option, the JAR file
    is the source of all user classes,
    and other user class path settings are ignored.

    • java command line usage
    • manifest spec

    (Notes: JAR files can be inspected with most ZIP applications; I probably neglect handling spaces in directory names in the batch script; Scala code runner version 2.7.4.final .)


    For completeness, an equivalent bash script:

    #!/bin/bash
    
    if [ ! $SCALA_HOME ]
    then
        echo ERROR: set a SCALA_HOME environment variable
        exit
    fi
    
    if [ ! -f scala-library.jar ]
    then
        cp $SCALA_HOME/lib/scala-library.jar .
    fi
    
    scalac -sourcepath src -d bin src/foo/HelloWorld.scala
    
    cd bin
    jar -cfm ../hellow.jar ../MANIFEST.MF *
    cd ..
    
    java -jar hellow.jar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, it partly depends on the exact type of list.… May 12, 2026 at 12:19 am
  • Editorial Team
    Editorial Team added an answer Don't get sucked in by the FQA troll. As usual… May 12, 2026 at 12:19 am
  • Editorial Team
    Editorial Team added an answer As I wrote in some other answer to one of… May 12, 2026 at 12:19 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.