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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:52:39+00:00 2026-05-29T08:52:39+00:00

Problem: I wrote a hello world java program, compiled and created a jar file

  • 0

Problem: I wrote a hello world java program, compiled and created a jar file of it – PERFECT, no problems there.

I now added the following to the top of the source code

package za.ac.uj.csc2a;

saved the code, place all the files in the right directories and every time i compile with this batch file

del *.class
del *.jar
del *.txt

echo compiling HelloWorld.java.....

javac HelloWorld.java

javap -c HelloWorld.class > ByteCode.txt

jar cfe HelloWorld.jar HelloWorld HelloWorld.class

java -jar za.ac.uj.csc2a.HelloWorld.jar

i get,

Error: Unable to acces jarfile za.ac.uj.csc2a.HelloWorld.jar

Any Advice….


Here is the final bat file that works

del *.class
del *.jar
del *.txt
RD /Q /S bin

echo compiling HelloWorld.java.....

MD bin

javac -d bin za/ac/uj/csc2a/HelloWorld.java
javap -c bin/za/ac/uj/csc2a/HelloWorld.class > ByteCode.txt
jar cfe HelloWorld.jar za.ac.uj.csc2a.HelloWorld -C bin .
java -jar HelloWorld.jar
pause

thanks alot

Aiden

  • 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-29T08:52:40+00:00Added an answer on May 29, 2026 at 8:52 am

    Your jar is named Helloworld.jar:

     jar cfe HelloWorld.jar HelloWorld HelloWorld.class
    

    But you call it with the package name as prefix to the jar:

     java -jar za/ac/uj/csc2a/HelloWorld.jar
    
     java -jar HelloWorld.jar
    

    should be right.

    Normally, you put your classes and sources in different directories, if you use packages. A typical tree looks like

    proj
    |-- src
    |   |-- za
    |       |-- ac
    |           `-- HelloWorld.java
    |-- bin
        |-- za
            |-- ac
                `-- HelloWorld.class
    

    You can move to the src-directory, and compile with:

     javac -d ../bin za/ac/HelloWorld.java
    

    (reduced the package/path length for convenience) This will produce the directory structure in bin if needed (or often classes)

    Then, to jar the whole thing with the correct directory structure, you change to proj, and issue:

    jar cfe HelloWorld.jar za.ac.HelloWorld -C bin . 
    

    The dot stands for the whole directory.

    jar -help 
    

    will tell you more options. To create a runnable jar you need a manifest too. Else you can start your app:

    java -cp HelloWorld.jar za.ac.HelloWorld 
    

    (shortened the path a bit again).

    Note, that the structure of the directory has to reflect the package declaration. You can’t omit a part (za), and step into the next directory (ac). The class to run is za.ac.HelloWorld and therefor it is searched for in za/ac/ – no matter whether in the file system or in the jar.

    If you learn to issue the commands from the right base, it is easy. If not, you’ll get years of trial and error.

    For a jar which can be startet with java -jar, you need a manifest. A template is generated by the jar command. There you add

    Main-Class: za.ac.HelloWorld
    

    with a following blank line. Again: the whole name with package is needed. Main-Class can’t be written as Mainclass. HelloWorld must not be followed by .class or .java – common mistakes! But as you know, you may use the -e switch to specify the main class, but again: Include the package name.

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

Sidebar

Related Questions

There is a java file, which has some dependencies jars. But now, I don't
This is my first C program. hello world! I'm sure this is no problem
I wrote a program to solve a complicated problem. This program is just a
I wrote simple load testing tool for testing performance of Java modules. One problem
I'm attempt to debug a program I wrote, but I'm running into a problem
I wrote the following example program but it crashes with segfault. The problem seems
I wrote a simple 'Hello, world' application in C++ using Visual Studio 2008. I
I have a bunch human reading simple sentence (hello world) as a wav file,
Hey I just wrote a Hello World code for ASP. But it is not
I noticed people wrote about this circular reference problem quite a bit before but

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.