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 7630207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:02:34+00:00 2026-05-31T06:02:34+00:00

I created a Java application and need to prepare it to run on any

  • 0

I created a Java application and need to prepare it to run on any OS. For Windows I created a batch file like this launch-win32.bat:

@echo off
javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.package.MyMainClass

For linux I created a shell script like this launch-linux.sh:

#!/bin/sh
java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass

Now I thought MacOS will be quite similar to linux as both are unix based and I asked a friend with a mac to try to run the shellscript to launch my application. But it failed with the following NoClassDefFoundError:

Exception in thread "main" java.lang.NoClassDefFoundError: my/package/MyMainClass
Caused by: java.lang.ClassNotFoundException: my.package.MyMainClass
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

It looks like the syntax of the java command is not correct as the classpath is not properly added to the java programm. My main problem now is the following:

  1. MacOS is not officially supported by Sun/Oracle that’s why it’s difficult to find some good documentation. (I need the latest JRE 7).
  2. I never used any Mac or don’t have any to try out how it could work.

So my questions are now:

  1. How to run java from command line in MacOS, what’s the correct syntax? Or why does the command above not work? (For example the main difference between Windows and Linux is using semicolon ; instead of colon : separator for the classpath.)
  2. How should a MacOS script file should be named? .sh or .scpt or .command or is it like in linux that the file ending doesn’t matter as long as you chmod +x the script file?

Thanks for any hints.

  • 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-31T06:02:35+00:00Added an answer on May 31, 2026 at 6:02 am

    Okay, after some hours of research it seems there are more than just one answer to this issue(s).

    Bash scripts

    • The simplest way to create scripts in Mac OS seems to be the .command bash script files. They look quite similar to linux shell scripts. Make them executable like shell scripts with chmod +x.

    Multiple issues

    • One reason for the NoClassDefFoundError can be that the default installed Java VM on Mac OS is lower than the needed JRE/JDK which was used compiling the software. Nothing more I can do about that than just telling the user to install the lateste JRE.
    • Another reason for the NoClassDefFoundError is – and this is quite shocking – that bash scripts in Mac OS don’t run from within the same directory as where they are located in but from the user’s home directory. The solution is to add a line to the bash script to find out the working directory: cd "$(dirname "$0")" (See also.)

    Summary

    Windows: launch-win32.bat

    @echo off
    javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.package.MyMainClass
    

    Linux: launch-linux.sh

    #!/bin/sh
    java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass
    

    Mac OS: launch-macos.command

    #!/bin/bash
    cd "$(dirname "$0")"
    java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing a problem when I need to distribute my java application, created using
I have created a java application and packed it into a jar file on
I'm using Netbeans 6.7.1 on Windows. I created a Java application using Swing. When
I've created a Java EE application using a set of libraries. Works like a
I have created a fairly substantial Java GUI application with many form windows where
I have recently created a java application(calculator) in netbeans and need to make it
I created java ee application with this tutorial: http://prideafrica.blogspot.com/2007/04/simple-authentication-servlet-filter.html but I do not know
I've created a stand alone java application in which i need to copy files
I've created an Java EE application on Glassfish and it's deployed and run successfully.
I created java enterprise application and it consists of ejb module and web application.

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.