简体   繁体   English

Class ClassNotFoundException 加载问题

[英]Class loading issue with ClassNotFoundException

I have a piece of code which works in one environment and fails with another one.我有一段代码可以在一个环境中工作而在另一个环境中失败。 For some reason a class loading fails.由于某种原因,class 加载失败。 I ran the application with a -verbose flag to check for differences but I cannot find the reason.我使用 -verbose 标志运行应用程序以检查差异,但找不到原因。 The class causing problems is org.apache.commons.configuration2.PropertiesConfiguration导致问题的 class 是org.apache.commons.configuration2.PropertiesConfiguration

Other classes from the same library seem to be loaded without issues before.来自同一库的其他类之前似乎没有问题地加载过。

This is a piece of output where the error occurs:这是发生错误的output的一段:

[52.212s][info][class,load  ] org.apache.commons.beanutils.BeanUtils source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/../../../../../../../git-repositories/knime-scripting/de.mpicbg.knime.scripting.libs/lib/commons-beanutils-1.9.4.jar
[52.213s][info][class,load  ] org.apache.commons.configuration2.io.FileHandler$Updater source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/../../../../../../../git-repositories/knime-scripting/de.mpicbg.knime.scripting.libs/lib/commons-configuration2-2.8.0.jar
[52.213s][info][class,load  ] org.apache.commons.configuration2.io.FileHandler$9 source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/../../../../../../../git-repositories/knime-scripting/de.mpicbg.knime.scripting.libs/lib/commons-configuration2-2.8.0.jar
[52.213s][info][class,load  ] org.apache.commons.configuration2.convert.DefaultListDelimiterHandler source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/../../../../../../../git-repositories/knime-scripting/de.mpicbg.knime.scripting.libs/lib/commons-configuration2-2.8.0.jar
[52.213s][info][class,load  ] org.apache.commons.configuration2.builder.EventListenerProvider source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/../../../../../../../git-repositories/knime-scripting/de.mpicbg.knime.scripting.libs/lib/commons-configuration2-2.8.0.jar
[52.213s][info][class,load  ] org.apache.commons.configuration2.builder.BasicConfigurationBuilder$$Lambda$1498/0x0000000801c16698 source: org.apache.commons.configuration2.builder.BasicConfigurationBuilder
[52.214s][info][class,load  ] org.apache.commons.configuration2.builder.BasicConfigurationBuilder$1 source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/../../../../../../../git-repositories/knime-scripting/de.mpicbg.knime.scripting.libs/lib/commons-configuration2-2.8.0.jar
[52.214s][info][class,load  ] org.apache.commons.lang3.ClassUtils source: file:/Users/niederle/knimeDev/SDK/Eclipse-workspaces/eclipse_2022-07/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.apache.commons.lang3_3.9.0.jar
FATAL    AWT-EventQueue-0 RGGDialogPanel     org.apache.commons.configuration2.ex.ConfigurationRuntimeException: java.lang.ClassNotFoundException: org.apache.commons.configuration2.PropertiesConfiguration
[52.215s][info][class,load  ] java.lang.Throwable$PrintStreamOrWriter source: jrt:/java.base
[52.215s][info][class,load  ] java.lang.Throwable$WrappedPrintStream source: jrt:/java.base
org.apache.commons.configuration2.ex.ConfigurationRuntimeException: java.lang.ClassNotFoundException: org.apache.commons.configuration2.PropertiesConfiguration
    at org.apache.commons.configuration2.beanutils.BeanHelper.fetchBeanClass(BeanHelper.java:427)
    at org.apache.commons.configuration2.beanutils.BeanHelper.createBeanCreationContext(BeanHelper.java:475)
    at org.apache.commons.configuration2.beanutils.BeanHelper.createBean(BeanHelper.java:353)
    at org.apache.commons.configuration2.beanutils.BeanHelper.createBean(BeanHelper.java:371)
    at org.apache.commons.configuration2.beanutils.BeanHelper.createBean(BeanHelper.java:383)
    at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResultInstance(BasicConfigurationBuilder.java:361)
    at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.createResult(BasicConfigurationBuilder.java:338)
    at org.apache.commons.configuration2.builder.BasicConfigurationBuilder.getConfiguration(BasicConfigurationBuilder.java:234)
    at at.ac.arcs.rgg.RGG.initRGG(Unknown Source)

while this is a piece of output where I do not get any error:虽然这是 output 的一部分,但我没有收到任何错误:

[45.850s][info][class,load] org.apache.commons.beanutils.BeanUtils source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-beanutils-1.9.4.jar
[45.919s][info][class,load] org.apache.commons.configuration2.io.FileHandler$Updater source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-configuration2-2.8.0.jar
[45.919s][info][class,load] org.apache.commons.configuration2.io.FileHandler$9 source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-configuration2-2.8.0.jar
[45.948s][info][class,load] org.apache.commons.configuration2.convert.DefaultListDelimiterHandler source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-configuration2-2.8.0.jar
[45.955s][info][class,load] org.apache.commons.configuration2.builder.EventListenerProvider source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-configuration2-2.8.0.jar
[248.267s][info][class,load] org.apache.commons.configuration2.builder.BasicConfigurationBuilder$$Lambda$144/0x0000000800d03740 source: org.apache.commons.configuration2.builder.BasicConfigurationBuilder
[248.280s][info][class,load] org.apache.commons.configuration2.builder.BasicConfigurationBuilder$1 source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-configuration2-2.8.0.jar
[248.313s][info][class,load] org.apache.commons.lang3.ClassUtils source: file:/Users/niederle/knimeDev/git-repositories/rgg/lib/commons-lang3-3.9.jar
[248.316s][info][class,load] java.lang.NumberFormatException source: jrt:/java.base
[248.325s][info][class,load] java.lang.invoke.LambdaForm$DMH/0x0000000800d06000 source: __JVM_LookupDefineClass__
[248.326s][info][class,load] java.lang.invoke.MethodHandle$1 source: jrt:/java.base
[248.335s][info][class,load] java.lang.invoke.LambdaForm$DMH/0x0000000800d06400 source: __JVM_LookupDefineClass__
[248.340s][info][class,load] org.apache.commons.configuration2.PropertiesConfiguration$$Lambda$145/0x0000000800d07000 source: org.apache.commons.configuration2.PropertiesConfiguration
[248.345s][info][class,load] org.apache.commons.configuration2.PropertiesConfiguration$$Lambda$146/0x0000000800d07220 source: org.apache.commons.configuration2.PropertiesConfiguration

I am not sure whether this is the right way to troubleshoot or whether it gives me some hint but I don't see it.我不确定这是否是解决问题的正确方法,或者它是否给了我一些提示,但我没有看到。 I would be happy if anybody could help troubleshooting.如果有人可以帮助排除故障,我会很高兴。 Do I need to provide more information?我需要提供更多信息吗? Jars provided should be the same in both environments.提供的 Jars 在两个环境中应该相同。


EDIT:编辑:

I went on with troubleshooting and still don't get the problem.我继续进行故障排除,但仍然没有解决问题。

This is the piece of code causing trouble.这是导致麻烦的代码段。 While class loading with Class.forName() seems to work, the second part of the code fails with the error mentioned above.虽然 class 加载Class.forName()似乎有效,但代码的第二部分失败并出现上述错误。 In the second part, the class is attempted to be loaded somewhere within builder.getConfiguration() via beanutils .在第二部分中,尝试通过beanutils将 class 加载到builder.getConfiguration()中的某处。

config = new CompositeConfiguration();
try {
    Class.forName("org.apache.commons.configuration2.PropertiesConfiguration");
} catch (ClassNotFoundException e1) {
    System.out.println("failed to load class");
    e1.printStackTrace();
}
FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
        new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
                    .configure(new Parameters().properties()
                    .setURL(RGG.class.getResource("/at/ac/arcs/rgg/config/elementfactory.properties"))
                    .setThrowExceptionOnMissing(true)
                    .setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
                    .setIncludesAllowed(false));
System.out.println("builder initialized");
PropertiesConfiguration newConfig;
try {
    newConfig = builder.getConfiguration();
    config.addConfiguration(newConfig);
} catch (ConfigurationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

If this is a library access issue.如果这是库访问问题。 How would I troubleshoot?我将如何排除故障?

The setup where it fails is the following: The code is part of a jar which is used as a library for an Eclipse plugin (me as author) written for a RCP application (not from me).它失败的设置如下:代码是 jar 的一部分,它用作为 RCP 应用程序(不是我)编写的 Eclipse 插件(我作为作者)的库。

Finally, I could solve my issue最后,我可以解决我的问题

I made some mistake here: The full stack trace could have been useful for troubleshooting.我在这里犯了一些错误:完整的堆栈跟踪可能对故障排除很有用。 Further the setup (not working within an Eclipse plugin) seemed to play an important role.此外,设置(不适用于 Eclipse 插件)似乎发挥了重要作用。

As far as I understood it, the issue has been caused like this:据我了解,问题是这样引起的:

RGG.jar (library within my plugin) is dependent on commons-configuration (library in my plugin). RGG.jar (我的插件中的库)依赖于commons-configuration (我的插件中的库)。 But then within commons-configuration a class from the same package has to be loaded with ClassUtils of commons-lang .但是随后在commons-configuration中,来自同一个 package 的 class 必须加载commons-langClassUtils But commons-lang is provide from outside as Required Plug-ins .但是commons-lang是作为Required Plug-ins从外部提供的。 It seems that it cannot access this class from outside.好像不能从外面访问这个class。

The solution I found was to add commons-lang as a library to that plugin and delete the dependency.我找到的解决方案是将commons-lang作为库添加到该插件并删除依赖项。 Now class loading works.现在 class 加载工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在运行时在Java中加载类ClassNotFoundException - loading class at runtime in java ClassNotFoundException Java-父类的ClassNotFoundException中的类加载结果 - Java - class loading results in ClassNotFoundException for parent class 从JAR加载类时发生ClassNotFoundException - ClassNotFoundException when loading class from JAR 动态加载类文件时抛出ClassNotFoundException - ClassNotFoundException Thrown when Dynamically Loading Class Files JVM类加载中出现意外行为(真正需要类之前的ClassNotFoundException) - Unexpected behaviour in JVM class loading (ClassNotFoundException before the class is really needed) 类加载问题 - Class loading issue RuntimeException,ClassNotFoundException:类WordCount $找不到Map。 Mapper类问题 - RuntimeException, ClassNotFoundException: Class WordCount$Map not found . Mapper class issue 从运行时加载的 java 9 模块加载 class 时发生 ClassNotFoundException - ClassNotFoundException while loading class from a java 9 module that was loaded at runtime 使用 URLClassLoader 加载类时出现 java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when loading class with URLClassLoader 从jar文件加载类时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when loading a class from a jar file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM