JUnit error with java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Tycho environment

I have a very strange situation. I have a set of eclipse plugin projects that I use tycho and maven to create. I used the JDBC driver in one of the projects, and I have a test plugin to test this project. Since the com.mysql.jdbc plugin is not available in the eclipse p2 repository (and we do not have our own p2), I imported the jdbc plugin and created the OSGi plugin and added the dependency to my local plugin.

I have many eclipse workspaces. Only in the very first workspace that created the test and jdbc plugins do junit tests work when I run them using the eclipse run -> Junit test command. When others or even me check the source code and try to run the test in different workspaces, this exception is thrown:

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

I also tried using the tycho integration test (running mvn integration-test), but this does not work, and I still get the same exception. I tried looking for this a lot, but I could not find the answer.

UPDATE: I think this is not a tycho problem. I just tried creating a java based eclipse plugin. Com.jdbc.mysql. The workspace that I created works fine. But as soon as I pass the code and import the project into another workspace, the tests stop working. All settings are the same for two workspaces: one works, the other gets a ClassNotFound exception!

0
source share
2 answers

Tycho calculates OSGi runtime based on the transitive dependencies of your test suite. You probably have no dependency on development time for the mysql driver package (but rather, only on the JDBC interfaces that it implements)

Try adding a test runtime dependency to the mysql jdbc driver package. See http://wiki.eclipse.org/Tycho/FAQ#How_to_add_a_undeclared_dependency.3F__.28e.g..2C_OSGi_declarative_service.29 on how to do this.

0
source

ClassNotFoundException at OSGi runtime indicates that there is something wrong with the import and / or export declarations in the OSGi manifest. The most common case is that a package requires exporting a specific package, but actually does not have binary files / classes of this package.

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

0
source

All Articles