本文介绍了JUnit测试失败,并在Tycho环境上出现java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的情况.我有一组eclipse插件项目,我正在使用tycho和maven来构建它们.我在其中一个项目中使用了JDBC驱动程序,并且我有一个测试插件来测试该项目.由于com.mysql.jdbc插件在eclipse p2存储库中不可用(并且我们没有自己的p2),因此我导入了jdbc插件并创建了OSGi插件,并将依赖项添加到我的本地插件中.

I have a very strange situation. I have a set of eclipse plugin projects which I am using tycho and maven for building them. I used JDBC driver in one of the projects and I have a test plugin to test this project. Since the com.mysql.jdbc plugin was not available in the eclipse p2 repository ( and we don't have our own p2), I imported the jdbc plugin and created an OSGi plugin and add the dependency to my local plugin.

我有多个月食工作区.只有在创建test和jdbc插件的第一个工作区中,当我使用eclipse as-> Junit test命令运行它们时,junit测试才能正常工作.当其他人甚至我签出源代码并尝试在不同的工作空间中运行测试时,会抛出此异常:

I have multiple eclipse workspaces sat up. Only in the very first workspace that created the test and jdbc plugin, junit tests are working when I run them using eclipse run as -> Junit test command. When others or even me checkout the source codes and try to run the test in different workspaces, this exception is thrown:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

我也尝试过使用tycho集成测试(运行mvn集成测试),但这都不起作用,而且我仍然遇到相同的异常.我尝试了很多搜索,但找不到答案.

I also tried using tycho integration test (runing mvn integration-test) but that doesn't work neither and I still get the same exception. I tried searching for this a lot but I couldn't find the answer.

更新:我认为这不是错综复杂的问题.我只是尝试基于com.jdbc.mysql jar创建eclipse插件.我在其上创建的工作区工作正常.但是,一旦我提交代码并将项目导入另一个工作区中,测试就会停止工作.在两个工作空间中,所有设置都是相同的,一个正在工作,另一个则收到ClassNotFound异常!

UPDATE:I think it is not a tycho problem. I just tried to create the eclipse plug in based on com.jdbc.mysql jar. The workspace I created this on is working fine. But as soon as I commit the code and import the project in another workspace the tests stop working. All of the settings are same among two workspaces, one is working the other gets the ClassNotFound exception!

推荐答案

ClassNotFoundException s指示OSGi清单中的导入和/或导出声明中存在错误.最常见的情况是,捆绑软件声称要导出某个程序包,但实际上没有该程序包的二进制文件/类文件.

ClassNotFoundExceptions in an OSGi runtime indicate that there is something wrong in the imports and/or export declarations in the OSGi manifests. The most frequent case is that a bundle claims to export a certain package, but doesn't actually have the binaries/class files of that package.

在Tycho版本中,如果build.propertiesbin.includes属性中没有条目.,则很容易发生这种情况.

In a Tycho build, this can easily happen if you don't have the entry . in the bin.includes property in the build.properties.

这篇关于JUnit测试失败,并在Tycho环境上出现java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:59