Eclipse rcp - how to load jdbc driver?

為{幸葍}努か 提交于 2020-01-24 12:43:26

问题


I was wondering if someone could give me some instructions on how to do the following:

  1. How to add mysql connection JAR file to the Eclipse plugin build path
  2. How to add the connector JAR file as library and adding to the plugin's runtime classpath

I am getting com.mysql.jdbc.Driver exception when trying to load the Driver class using Class.forName("com.mysql.jdbc.Driver"). I have added the jdbc driver to the project by right clicking on the project name and selecting add Library button. But I found out there for eclipse rcp project there is a different way of adding the jdbc jar file.


回答1:


I've never used mysql with Eclipse, but i've done this with postgres sql. Maybe this will help you:

  • Right-click project in Package explorer
  • Build path
  • Add external archives...
  • Select your mysql jar archive
  • Press OK
  • The library should be now referenced in the "Referenced Librairies" under the Package explorer. Now try to run your program again.



回答2:


Add your jdbc driver jar to the bundle classpath (every RCP plugin is a OSGi bundle). To do it you can edit META-INF/MANIFEST.MF directly or use manifest editor provided by PDE (classpath section under Runtime tap).

In general, you should never edit plugin projects classpath directly.




回答3:


  1. run "PDE Tools / Update classpath";

  2. the mysql jar must in the project lib dir.

  3. in project "Java build path", select the mysql jar in lib dir of the project.




回答4:


Do use DynamicImport-Package: * in the MANIFEST.MF of the jar-plugin having mysql.jar as Runtime classpath. It helps Class.forName("com.mysql.jdbc.Driver") importing wanted packages.



来源:https://stackoverflow.com/questions/5956936/eclipse-rcp-how-to-load-jdbc-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!