创建.jar文件

时间:2011-12-22 23:01:01

标签: java user-interface jar creation

我正在创建一个包含GUI的.jar文件:

jar cmf mainClass patcherFull.jar pack

我上面的创建命令没有错误,但是然后运行.jar文件在Windows中什么都不做,并用java本身输出它:

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"

这是我的代码结构:

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();
          }
        });
    }
}

这是我的mainClass清单文件(最后有一个新行):

Main-Class: patcherFull

我的代码结构中有什么问题吗?作为一个FYI,“pack”文件夹包含3个生成的.class文件,2个依赖项(jpg和exe),然后是“patcherFull.java”文件。

以下是有关.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

1 个答案:

答案 0 :(得分:2)

您的主要类应该是pack.patcherFull,而不是patcherFull,以符合您在jar文件中的结构。

另请注意,约定规定它应为pack.PatcherFull