将Java项目导出为runnable Jar:没有做任何事情

时间:2015-11-21 22:10:38

标签: java eclipse jar runnable

所以导出我的eclipse项目有问题。 该项目在eclipse中运行时效果很好,但在导出时,它没有做任何事情。

enter image description here

enter image description here

我不能发布第三个链接,因为我的声誉不到10,但在那里我选择了我的“main”作为启动配置,并且“包所需的库。

当我双击可运行的Jar时,没有任何事情发生,没有任何东西弹出......没有任何消息。 当我使用java -jar smergy.jar运行时,我会收到

`C:\Users\Jean>java -jar Smergy.jar
java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(Unknown Source)
        at smergy.SmergyMain.<init>(SmergyMain.java:162)
        at smergy.SmergyMain$1.run(SmergyMain.java:50)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)`

1 个答案:

答案 0 :(得分:1)

很可能图像没有被打包到罐子里。或者他们没有被加载。 处理加载资源的一种方法是使用Toolkit,如下所示:     setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/package1/package2/dump.jpg")));