包含依赖项的ClassNotFoundException [英] ClassNotFoundException for included dependency

查看:152
本文介绍了包含依赖项的ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven在我的项目中包含google gdata模块,所有内容编译都很好,但我得到了这个运行时异常:

I'm using maven to include the google gdata module in my project and everything compiles fine, but I get this runtime exception:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gdata/util/ServiceException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
    at java.lang.Class.getMethod0(Class.java:2813)
    at java.lang.Class.getMethod(Class.java:1663)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: com.google.gdata.util.ServiceException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 6 more

我将模块包含在我的pom中就像这样...

I'm including the module in my pom like so...

...
<dependencies>
    <dependency>
        <groupId>com.google.gdata</groupId>
        <artifactId>core</artifactId>
        <version>1.47.1</version>
    </dependency>
</dependencies>
...

并且包括在我的班级中......如此...

And including in my class like so...

...
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.docs.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.ListFeed;
import com.google.gdata.util.ServiceException;
...

当我打开依赖项并潜入罐子时,我看到了ServiceException类......那么给出了什么?我尝试下载这些资源只是为了好玩,但没有任何帮助。

When I open the dependencies and dive into the jars, I see the ServiceException class... so what gives? I tried downloading the sources just for fun, but didn't help with anything.

我确定这是傻事我做错了......

I'm sure it's something silly I'm doing wrong...

---更新---

我检查了注释中建议的重复依赖项。在发现其中一个依赖项包含在不同版本中之后,我更新了pom文件:

I checked for duplicate dependencies like suggested in the comments. After finding that one of the dependencies was being included with different versions, I updated the pom file:

<dependency>
    <groupId>com.google.gdata</groupId>
    <artifactId>core</artifactId>
    <version>1.47.1</version>
    <type>jar</type>
    <exclusions>
        <exclusion>
            <artifactId>jsr305</artifactId>
            <groupId>com.google.code.findbugs</groupId>
        </exclusion>
    </exclusions>
</dependency>

番石榴仍然存在版本差异,但即使不包括番石榴也不会破坏构建(和依赖树只将它标记为警告)我仍然得到相同的错误,所以我不认为这是问题所在。无论如何,这个类都在gdata核心模块中......

There's still a version discrepancy for guava, but even excluding guava entirely doesn't break the build (and the dependency tree only marks it as a warning) and I still get the same error, so I don't think that's the problem. The class is in that gdata core module anyway...

字面上,我项目中唯一的其他类是一个非常稀疏的枚举类,我已经列出了所有类我包含的非核心java类。

Literally the only other class I have in my project is a pretty sparse enum class, and I've listed all non core-java classes that I include.

我已经清理,删除.m2构建,重建,同样的问题。

I've cleaned, deleted .m2 built, rebuilt, same problem.

推荐答案

显然,在类路径下找不到 com.google.gdata.util.ServiceException class。

Obviously, com.google.gdata.util.ServiceException class can't be found under your classpath.


  1. 尝试再次从命令行和项目文件夹中提取依赖项: dependency:copy-dependencies

  2. 尝试通过刷新项目来同步您的eclipse IDE,和/或通过更新依赖项通过m2e eclipse插件来同步。

  3. On命令行&从您的项目文件夹尝试再次编译使用: mvn clean compile

  4. 如果这不起作用,请查看下面的不合适的类您项目中的Maven依赖项(您应该能够找到)

  5. 确保您的Maven依赖项是构建配置的一部分。尝试再次编译: mvn clean compile

  1. Try to pull the dependencies again, from command-line and from your project folder: dependency:copy-dependencies
  2. Try to sync your eclipse IDE by refreshing the project, and/or by m2e eclipse plugin by update dependencies.
  3. On command-line & from your project folder try to compile again using: mvn clean compile
  4. If that doesn't work, look for the unfound class under Maven dependencies in your project, (you should be able to find)
  5. Make sure your Maven dependencies are a part of your build configuration. Try to compile again: mvn clean compile

如果您有请求的依赖项在您的本地Maven存储库中,它包含在您的项目中,您的构建配置包括要包含在输出类路径文件夹中的Maven依赖项。然后它应该工作。

If you have the requested dependency in your Local Maven Repository, and it's included in your project, and your build configuration includes the Maven dependencies to be included in your output classpath folder. Then it should work.

这篇关于包含依赖项的ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆