carget
carget

Reputation: 77

Creating a .jar file

I'm creating a .jar file that has a GUI:

jar cmf mainClass patcherFull.jar pack

I get no errors with the creation command above, but then running the .jar file does nothing in Windows, and running it with java itself outputs:

java -jar patcherFull.jar
java.lang.NoClassDefFoundError: patcherFull
Caused by: java.lang.ClassNotFoundException: patcherFull
        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: patcherFull. Program will exit.
Exception in thread "main"

This is my code structure:

public class patcherFull extends JPanel implements ActionListener, PropertyChangeListener
{

  private JProgressBar progressBar;
  private JButton startButton, closeButton;
  private JLabel status;
  private Task task;

    class Task extends SwingWorker<Void, Void> {
        @Override
        public Void doInBackground()
        {
        }

        @Override
        public void done()
        {
        }
    }

    public patcherFull()
    {
  }

    public void actionPerformed(ActionEvent evt)
    {
    }

    public void propertyChange(PropertyChangeEvent evt)
    {
    }

    private static void createAndShowGUI()
    {
    }

    public static void main(String[] args)
    {
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                createAndShowGUI();
          }
        });
    }
}

This is my mainClass manifest file (with a new line at the end):

Main-Class: patcherFull

Is there something wrong within my code structure? And as an FYI, the "pack" folder has the 3 generated .class files, 2 dependencies (a jpg and an exe) and then the "patcherFull.java" file.

Here is some more info on what's inside the .jar:

$ jar tf patcherFull.jar
META-INF/
META-INF/MANIFEST.MF
pack/
pack/banner.jpg
pack/patcherFull$1.class
pack/patcherFull$Task.class
pack/patcherFull.class
pack/patcherFull.java
pack/wget.exe

Upvotes: 0

Views: 506

Answers (1)

Your main class should be pack.patcherFull, not patcherFull, to conform to your structure in the jar file.

Also note that convention dictates that it should be pack.PatcherFull.

Upvotes: 2

Related Questions