如何创建与NetBeans可执行.jar文件 [英] How to create executable .jar file with netbeans

查看:264
本文介绍了如何创建与NetBeans可执行.jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使双击CLI应用程序,但仍然没有得到如何。
我知道我应该propably莫名其妙编辑清单,但仅此而已。我GOOGLE了OFC。但没有成功。
感谢您的任何提示。
下面是构建输出,运行和清单:

 编译:
创建目录:/家居/尼克/的NetBeansProjects / SemestralWork / DIST
大厦罐子:/home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar
不是复制库。
若要从没有蚂蚁在命令行这个应用程序,请尝试:
Java的罐子/home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar
罐:
BUILD SUCCESSFUL(总时间:1秒)
Java的罐子/home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar异常线程mainjava.lang.NoClassDefFoundError的:semestralwork /主
抛出java.lang.ClassNotFoundException:引起semestralwork.Main
    在java.net.URLClassLoader的$ 1.run(URLClassLoader.java:217)
    在java.security.AccessController.doPrivileged(本机方法)
    在java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    在java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:294)
    在java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    在java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
找不到主类:semestralwork.Main。计划将退出。我的清单与建设创建:清单-版本:1.0蚂蚁版本:Apache Ant的1.7.1创建-者:14.0 - B08(Sun微系统公司)主类:semestralwork.Main类路径:的X注释:主类将自动生成添加


解决方案

这两行告诉你所有你需要知道的:

 异常线程mainjava.lang.NoClassDefFoundError的:semestralwork /主
抛出java.lang.ClassNotFoundException:引起semestralwork.Main

和进一步的线索是由清单输出下降:

 主类:semestralwork.Main

这意味着JAR文件正在寻找一个名为包 semestralwork 和一个名为里面类。它未能在这一点上,因为它不能找到任何的 semestralwork 包或类。

正如你在提问时指出,这个问题确实是在manifest文件。你可以,如果你想在你的JAR文件中直接编辑这一点,但一个更好的想法是从NetBeans中做到这一点:


  • 单击上'文件 - >项目属性(semestralwork)

  • 在打开,在左侧的树中选择对话框运行

  • 然后,在右侧,标有场下主类:,输入的完全合格的类名称的要执行的类在命令行运行时。

在你的情况,因为我从你的评论上看到@阿龙的回答,如果你的主类是在一个名为 encryption.java ,它是在默认包(没有包),只需输入加密

一旦做到这一点,做一个干净而建,然后尝试在命令行重新运行。

心连心

I'd like to make "double-click" cli application but still don't get how. I know I should propably somehow edit manifest but that is all. I googled ofc. but no success. Thanks for any tips. Here is the output from build, run, and manifest:

compile:
Created dir: /home/nick/NetBeansProjects/SemestralWork/dist
Building jar: /home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar
Not copying the libraries.
To run this application from the command line without Ant, try:
java -jar "/home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar"
jar:
BUILD SUCCESSFUL (total time: 1 second)


java -jar /home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar

Exception in thread "main" java.lang.NoClassDefFoundError: semestralwork/Main
Caused by: java.lang.ClassNotFoundException: semestralwork.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: semestralwork.Main. Program will exit.

MY MANIFEST created with build:

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.7.1

Created-By: 14.0-b08 (Sun Microsystems Inc.)

Main-Class: semestralwork.Main

Class-Path: 

X-COMMENT: Main-Class will be added automatically by build

解决方案

These two lines tell you all you need to know:

Exception in thread "main" java.lang.NoClassDefFoundError: semestralwork/Main
Caused by: java.lang.ClassNotFoundException: semestralwork.Main

And a further clue is dropped by the manifest output:

Main-Class: semestralwork.Main

This means that the JAR file is looking for a package named semestralwork and a class named Main inside it. It fails at this point because it cannot find either the semestralwork package or the Main class.

As you pointed out in your question, the problem is indeed in the manifest file. You can edit this directly in your JAR file if you like, but a better idea would be to do this from Netbeans:

  • Click on `File --> Project Properties (semestralwork)'
  • In the dialog that opens, on the tree on the left select Run
  • Then, on the right, under the field labeled Main class:, enter the fully qualified class name of the class that you want executed when run from the command line.

In your case, as I see from your comment on @Aaron's answer, if your main class is in a file called encryption.java, and it is in the default package (no package), just enter encryption.

Once this is done, do a clean and build, then try running it from the command line again.

HTH

这篇关于如何创建与NetBeans可执行.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆