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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:11:34+00:00 2026-06-12T21:11:34+00:00

I have successfully created a Java program that runs fine on my development computer,

  • 0

I have successfully created a Java program that runs fine on my development computer, both in Netbeans and with the .jar file (double clicking). The problem is that it won’t start on computers without JDK or without starting via command line with java -jar jarfile.jar (note that it won’t start without the -jar flag).

Neither on the development computer the jar file runs without the -jar flag on command line.

The error I’m getting in all the situations where the program doesn’t start is the following.

S:\Folder>Program.jar
Exception in thread "main" java.lang.NoClassDefFoundError: S:\Folder\Program/jar
Caused by: java.lang.ClassNotFoundException: S:\Folder\Program.jar
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: S:\Folder\Program.jar. Program will exit.

The file structure of Program.jar looks this:

Program.jar
    binlib
        build.xml
        manifest.mf
        onejar.mf
        one-jar-ant-task.xml
    com
        simontuffs
            onejar
                a lot of classes related to OneJar
    doc
        one-jar-license.txt
    lib
        itextpdf-5.3.3.jar
    main
        main.jar
            my
                package
                    all the classes related to my program
            META-INF
                manifest.mf
            Resources
                all my programs resources
            txt
                more resources
    META-INF
        MANIFEST.MF
    .version
    OneJar.class

The project is compiled with Netbeans and OneJar to get all the required libraries (in this case iText) in the same jar file to help the users – only one file is easier than two files.

The MANIFEST.MF file in the META-INF folder in the root of the jar file contains the following:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: One-Jar 0.97 Ant taskdef
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: my.package.MainClass
Class-Path: lib/itextpdf-5.3.3.jar

Note that this is automatically generated by OneJar so I suppose it’s right though the real path to the main class also contains /main/main.jar/ if the path is related to the root.

The MANIFEST.MF in the inner jar file (the actual program) is empty. The one in binlib folder contains the following:

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Main-Class: my.package.MainClass

How do I get the jar running?

  • 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-06-12T21:11:36+00:00Added an answer on June 12, 2026 at 9:11 pm

    The jar files won’t run without JDK, because Windows doesn’t call java.exe (or javaw.exe) correctly. When the user selects the default program to open jar files, Windows adds the following in the registry:

    "Path\To\JRE\Bin\java(w).exe" "%1"
    

    As you can see in the quote, the -jar flag is missing. When you install JDK, it will automatically correct these values.

    To fix this, you need a batch script to replace the wrong values. The registry entries that need to be repaired are jarfile, java.exe and javaw.exe.

    What I did was to deploy a jarfix.bat with the program with the instructions how to correctly “install” the program.

    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" /v "CurrentVersion" 1>nul
    if errorlevel 1 goto :error
    
    @FOR /F "tokens=2* " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" /v "CurrentVersion"') DO @SET JAVAVERSION=%%B
    
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\%JAVAVERSION%" /v "JavaHome" 1>nul
    reg query "HKEY_CURRENT_USER\SOFTWARE\Classes\Applications\java.exe" 1>nul
    reg query "HKEY_CURRENT_USER\SOFTWARE\Classes\Applications\javaw.exe" 1>nul
    if errorlevel 1 goto :error
    
    @FOR /F "tokens=2* " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\%JAVAVERSION%" /v "JavaHome"') DO @SET JAVAHOME=%%B
    @FOR /F "tokens=2* " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command" /v ""') DO @SET JAVACOMMAND=%%B
    @FOR /F "tokens=2* " %%A IN ('reg query "HKEY_CURRENT_USER\Software\Classes\Applications\java.exe\shell\open\command" /v ""') DO @SET JAVACOMMAND2=%%B
    
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command" /f /v "" /t REG_SZ /d "\"%JAVAHOME%\bin\javaw.exe\" -jar \"%%1\" %%*"
    reg add "HKEY_CURRENT_USER\Software\Classes\Applications\java.exe\shell\open\command" /f /v "" /t REG_SZ /d "\"%JAVAHOME%\bin\java.exe\" -jar \"%%1\" %%*"
    reg add "HKEY_CURRENT_USER\Software\Classes\Applications\javaw.exe\shell\open\command" /f /v "" /t REG_SZ /d "\"%JAVAHOME%\bin\javaw.exe\" -jar \"%%1\" %%*"
    

    The program will edit the registry so the program requires administrator privileges. To check them at the program startup, I did the following

    NET SESSION >nul 2>&1
    if %errorlevel% == 0 (
        echo  User successfully detected as an administrator!
    ) else (
        echo User doesn't have administrator privileges!
        exit /b 1
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a little program that reads in a Java file and feeds
I have successfully created an app that reads from a bundled .plist file and
Has anyone successfully created a NetBeans project that combines Clojure and Java source? I
I have created jar file for my project. It is running successfully. There is
I have a java program which creates a lock file to ensure that no
I have successfully created a Java class that provides database connectivity and returns a
I have successfully created a feature in sharepoint that modifies the existing edit dialog
I have created a Java project in Eclipse and successfully executed it directly from
I have successfully created a custom Facebook open graph action, and have been able
i have successfully created distribution profiles and installed on my xcode organiser, but 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.