运行时出现Unknown Source的问题

本文介绍了一种常见的情况,在使用自定义打包的Java类库时遇到UnknownSource错误,无法进行有效的源代码级调试。文章详细分析了问题的原因,并提供了解决方案,即在Ant打包脚本中添加debug属性。

问题描述:

      有一个web工程以来于几个java工程,发布时,需要将几个java工程达成jar包放到web工程,运行期间突然抛出异常,异常恰好时其中一个java工程的一个类抛出来的,但是抛出的异常信息里面含有Unknown Source,看不出异常发生在该类的哪个方法哪一行。打开jar中的该类,关联jar的源代码,设置断点,发现断点不起作用,怎么都没进去。

 

问题分析:

      怀疑1:开源的jar是不是也有这个问题,试过后发现开源的jar没有这个问题。

      怀疑2:自己打的jar包有问题,能够运行但不能调试,根据“Unknown Source“关键字到网上搜索一下,最终发现了问题所在。是ant打包时没有加一些属性导致的。

 

解决方法:

 

在ant的打包脚本上添加debug="true" debuglevel="source,lines,vars",具体如下:

 

 

<javac destdir="${build.classes}" srcdir="${src.java}"
classpathref="lib.classpath" encoding="utf-8" 
debug="true" debuglevel="source,lines,vars"/>
java.lang.NoClassDefFoundError: Could not initialize class jdk.nashorn.internal.parser.Lexer at jdk.nashorn.internal.parser.Parser.parse(Parser.java:275) at jdk.nashorn.internal.parser.Parser.parse(Parser.java:249) at jdk.nashorn.internal.runtime.Context.compile(Context.java:1286) at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1253) at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:625) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:532) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:521) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) at javax.script.AbstractScriptEngine.eval(Unknown Source) at com.sun.deploy.net.proxy.SunAutoProxyHandler.jsGetProxyInfo(Unknown Source) at com.sun.deploy.net.proxy.SunAutoProxyHandler.access$100(Unknown Source) at com.sun.deploy.net.proxy.SunAutoProxyHandler$2.run(Unknown Source) at com.sun.deploy.net.proxy.SunAutoProxyHandler$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.deploy.net.proxy.SunAutoProxyHandler.jsGetProxyInfo(Unknown Source) at com.sun.deploy.net.proxy.SunAutoProxyHandler.getProxyInfo(Unknown Source) at com.sun.deploy.net.proxy.DynamicProxyManager.getProxyList(Unknown Source) at com.sun.deploy.net.proxy.DeployProxySelector.select(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source) at com.cisco.launcher.s.new(Unknown Source) at com.cisco.launcher.s.actionPerformed(Unknown Source) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(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.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(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) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at com.cisco.launcher.s.new(Unknown Source) at com.cisco.launcher.s.actionPerformed(Unknown Source) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(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.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(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) 这个问题如何处理
10-01
Java exception occurred: java. lang. NoClassDefFoundError: Could not Initialize class sun. awt. Win32FontManager at java. lang. Class. forName(Native Method) at java. lang. Class. forName(Unknown Source) at sun. font. FontManagerFactory$1. run(Unknown Source) at java. security. AccessController. doPrivilege(Native Method) at sun. font. FontManagerFactory. instance(Unknown Source) at java. awt. Font. getFont2D(Unknown Source) at java. awt. Font. access$000(Unknown Source) at java. awt. Font$FontAccessImpl. getFont2D(Unknown Source) at sun. font. FontUtilities. getFont2D(Unknown Source) at sun. font. FontUtilities. fontSupportsDefaultEncoding(Unknown Source) at com. sun. java. swing. plaf. windows. WindowsLookAndFeel$WindowsFontProperty. configureValue(Unknown Source) at com. sun. java. swing. plaf. windows. DesktopProperty. createValue(Unknown Source) atjavax. swing. UIDefults. getFromHastable(Unknown Source) atjavax. swing. UIDefults. get(Unknown Source) atjavax. swing. MultiUIDefults. get(Unknown Source) atjavax. swing. UIDefults. getFont(Unknown Source) atjavax. swing. UIManager. getFont(Unknown Source) atjavax. swing. LookAndFeel. installColorsAndFont(Unknown Source) atjavax. swing. plaf. basic. BasicLabelUI. installDefaultS(Unknown Source) atjavax. swing. plaf. basic. BasicLabelUI. installUI(Unknown Source) atjavax. swing. JComponent. setUI(Unknown Source) atjavax. swing. JLabel. setUI(Unknown Source) atjavax. swing. JLabel. updateUI(Unknown Source) atjavax. swing. JLabel. <init>(Unknown Source) atjavax. swing. JLabel. <init>(Unknown Source) at com. mathworks. mwswing. MJLabel. <init>(MJLabel. java:72) at com. mathworks. mwswing. MJLabel. <init>(MJLabel. java:60) at com. mathworks. mwswing. MJStatusBar$田. <init>(MJStatusBar. java:275) at com. mathworks. mwswing. MJStatusBar. <clinit>(MJStatusBar. java:44) at com. mathworks.widgets. desk. DTProperty. <clinit>(DTProperty. java:392) at com. mathworks.widgets. desk.DTOoccupant. get
11-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值