博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java -jar 执行 eclipse export 的 jar 包报错处理
阅读量:5846 次
发布时间:2019-06-18

本文共 3754 字,大约阅读时间需要 12 分钟。

1. 错误1:打 jar 包执行,报错,找不到 类库的 jar 包

F:\>java -jar remoteLogin.jar

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSON
at com.diantusoft.LoginWindow.getFingerPrintFromDB(LoginWindow.java:819)
at com.diantusoft.LoginWindow.login(LoginWindow.java:630)
at com.diantusoft.LoginWindow.access$8(LoginWindow.java:577)
at com.diantusoft.LoginWindow$13.mouseClicked(LoginWindow.java:509)
at java.awt.Component.processMouseEvent(Component.java:6528)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4542)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:702)
at java.awt.EventQueue$3.run(EventQueue.java:696)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:724)
at java.awt.EventQueue$4.run(EventQueue.java:722)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: com.alibaba.fastjson.JSON
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

解决方法:Use Export -> Java -> Runnable JAR File instead Export -> Java -> JAR File on your project (right mouse click).

2. 错误2: Could not find main method from given launch configuration

原因:选错了 launch configuration,自然就找不到 main方法,选择时要选择那个包括 main 方法的 类作为 launch

3. 错误3:

1
2
3
4
5
public 
static 
ImageIcon getPicture2(String name) {
    
ImageIcon icon = 
new 
ImageIcon(PictureUtil.
class
.getClassLoader()
                            
.getResource(
"com/diantusoft/image/" 
+ name));
    
return 
icon;
}

如下代码,eclipse export 导出 jar 包之后,执行 无法找到路径:

因为路径变成了如下的形式:file:/F:/remoteLogin.jar!/com/diantusoft/image/login_button.png

所以 java -jar remoteLogin.jar 执行时,是如法找到图片的。

解决方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private 
static 
PictureUtil instance = 
new 
PictureUtil();
 
private 
PictureUtil(){}
 
 
public 
static 
PictureUtil getInstance(){
    
return 
instance;
}
 
public 
ImageIcon getPicture(String name){
    
URL url = 
this
.getClass().getResource(name);
     
    
if
(url != 
null
){   
        
return 
new 
ImageIcon(url);
    
}          
}

也就是使用 this.getClass().getResource() 来获取图片,就不会发生因路径变化找不到图片的问题。

转载于:https://www.cnblogs.com/jmsjh/p/7781045.html

你可能感兴趣的文章
1080*1920 下看网站很爽
查看>>
CMake 构建项目Android NDK项目基础知识
查看>>
MySQL 不落地迁移、导入 PostgreSQL - 推荐 rds_dbsync
查看>>
[Erlang 0004] Centos 源代码编译 安装 Erlang
查看>>
51 Nod 1027 大数乘法【Java大数乱搞】
查看>>
三维重建技术概述
查看>>
AI x 量化:华尔街老司机解密智能投资正确姿势
查看>>
IT史上十大收购案
查看>>
数据切分——Atlas介绍
查看>>
游戏引擎cocos2d-android使用大全
查看>>
oracle job 定时执行参数
查看>>
Android命令Monkey压力测试,详解
查看>>
负载均衡(LB)集群 dr
查看>>
(转)直接拿来用!最火的iOS开源项目(一)
查看>>
div+css+js 树形菜单
查看>>
android EventBus 3.0 混淆配置
查看>>
我的友情链接
查看>>
DNS区域委派与转发
查看>>
Windows Server 2008 RemoteApp---发布应用程序
查看>>
白帽子技术分析会话劫持实战讲解
查看>>