gpt4 book ai didi

Javassist 和 Webstart

转载 作者:行者123 更新时间:2023-11-29 06:04:56 24 4
gpt4 key购买 nike

这看起来像是一个已解决的老问题,但不幸的是我找不到好的引用资料。我有一个使用 Javaassist 的 Java 应用程序。在我将它升级到 webstart 应用程序之前,它工作正常。现在 Javaassist 给了我一个 classNotFoundException。不过,该类(class)肯定在类(class)路径中。

我发现这篇相关帖子 https://community.jboss.org/message/302408 有点旧,我无法解码它。有人可以帮我一下吗?

谢谢

这是代码片段:

 ctClasses = new HashMap<String, CtClass>();
classPool = ClassPool.getDefault();

try {
ctEntity = classPool.get("org.myclass");
} catch (NotFoundException e) {
logger.error("Could not find entity class, this should not happen");
throw new RuntimeException("Could not find Entity class",e);
}

堆栈跟踪中没有任何内容。

 java.lang.RuntimeException: Could not find Entity class
at ca.cbc.panacea.metadata.JavassistClassGeneratorImpl.<init>(JavassistClassGeneratorImpl.java:32)
at ca.cbc.panacea.metadata.ClassGeneratorFactory.getDefaultClassGenerator(ClassGeneratorFactory.java:12)
at ca.cbc.panacea.metadata.ClassCreator.<init>(ClassCreator.java:30)
at ca.cbc.panacea.Panacea.digestMappingFile(Panacea.java:75)
at ca.cbc.panacea.console.PanaceaConsole.validateMappingFile(PanaceaConsole.java:46)
at ca.cbc.panacea.console.PanaceaConsoleUI.actionPerformed(PanaceaConsoleUI.java:132)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6373)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6138)
at java.awt.Container.processEvent(Container.java:2085)
at java.awt.Component.dispatchEventImpl(Component.java:4735)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
at java.awt.Container.dispatchEventImpl(Container.java:2129)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:679)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:638)
at java.awt.EventQueue$1.run(EventQueue.java:636)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:652)
at java.awt.EventQueue$2.run(EventQueue.java:650)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:649)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: javassist.NotFoundException: ca.cbc.panacea.metadata.Entity
at javassist.ClassPool.get(ClassPool.java:436)
at ca.cbc.panacea.metadata.JavassistClassGeneratorImpl.<init> (JavassistClassGeneratorImpl.java:29)

问题实际上是ClassLoader。 JNLP 使用与 java 命令行不同的类加载器。问题是如何协调 JNLP 类加载器与 Javassist。

最佳答案

关键是设置 ClassPool 以查看应用程序类的类加载器。这可以通过向 ClassPool 添加类路径来完成:

ctClasses = new HashMap<String, CtClass>();
classPool = ClassPool.getDefault();

//Add the classloader of your application's classes so Javassist can find them
ClassLoader loader = org.MyClass.class.getClassLoader();
pool.appendClassPath(new LoaderClassPath(loader));

try {
ctEntity = classPool.get("org.MyClass");
} catch (NotFoundException e) {
logger.error("Could not find entity class, this should not happen");
throw new RuntimeException("Could not find Entity class",e);
}

您需要为任何不从系统类加载器加载其类的应用程序自定义类池的类路径,例如 Web 启动应用程序、Eclipse 插件和在 Java EE 容器下运行的应用程序。

更多详细信息在 Javassist tutorial类搜索路径 部分下.

关于Javassist 和 Webstart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8843714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com