Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370676 - very simply every which way I tried I cannot get org.postgresql.Driver to load at runtime
Summary: very simply every which way I tried I cannot get org.postgresql.Driver to loa...
Status: RESOLVED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: E4 (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-05 22:23 EST by Enver Stambouli CLA
Modified: 2012-12-13 15:00 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enver Stambouli CLA 2012-02-05 22:23:49 EST
Build Identifier:  I20120127-1145

I "Add external jar" in project properties un JAVA BUILD PATH I use 
Class.forName("org.postgresql.Driver"); get ClassNotFoundException;
I use the ClassLoader.loadClass("org.postgresql.Driver");  get ClassNotFoundException;
I tried pretty much every permutation to make postgresql-9.1-901.jdbc4.jar
visible I look in the .classpath file 
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="lib" path="D:/postgresql-9.1-901.jdbc4.jar"/>
	<classpathentry kind="output" path="bin"/>
</classpath>
There it is. Sorry if this not a bug or in the worng place it is the first time I find absolutely no answer on the web.... 
BTW I created another project in the workspace and with DTP I can connect using the same driver in the database connect definition so I got somewhere.... :/

I use eclipse Helios build 2 revision 20110218-0911
I have been using Eclipse software for a long time and love it but I always used to build my own java applications and alll my own classes for SQL work.

I am not a newbie at Java just the e4 JUNO flavor of it  :)

Again if this is not a bug I apologize but you are my last hope..
I have a bad feeling I am doing something wrong :(

Reproducible: Always

Steps to Reproduce:
1.New Project e4 -> e4 Application went to proect properties added Jar file as external jar(goes rightly in referenced Libraries)
2. added a command / Handler and a menu under MainMenu in Application.e4xmi
3. the Handler opens a login dialog box My own class extends Dialog
4. tried Class.forName there doesn't work 
5. tried Class.forName in activator doesn't work 
6. tried every permutation to load the jar even tried Utils4j.addToClassPath doesn't work 
//also tried 
7. tried to modify classpath/ tried to add vm argument in win32 Launching 
8. created a folder in the project called lib imported jar file in it and added 
to classpath under runtime Tab
9. import the jar into the root of the plugin 

No matter what I try I keep getting ClassNotFoundException
Comment 1 Enver Stambouli CLA 2012-02-05 22:29:09 EST
public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
		ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
		 
		try {
			
	             Class.forName("org.postgresql.Driver");
		     URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
			 
		     for(int i=0; i< urls.length; i++)
		     {
		         System.out.println(urls[i].getFile());
		     }       
		 
		}catch(ClassNotFoundException cnfe)
		{
			
	        //Get the URLs
	         URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
	 
	        for(int i=0; i< urls.length; i++)
	         {
	             System.out.println(urls[i].getFile());
	         }       
	        cnfe.printStackTrace();
		}
	}
java.lang.ClassNotFoundException: org.postgresql.Driver
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at com.ssesep.gashulub.Activator.start(Activator.java:32)
Comment 2 Paul Webster CLA 2012-02-06 08:39:09 EST
You need to write special handling to work with Java SQL drivers in an OSGi based (eclipse plugin) context.  Try asking how they load them correctly in the DTP forum.  You should also ask your questions on the plugin development environment forum.  See http://www.eclipse.org/forums/

See http://wiki.eclipse.org/The_Official_Eclipse_FAQs for more information on building eclipse plugins, and http://wiki.eclipse.org/PDE/User_Guide for a description of plugins as OSGi bundles, and http://wiki.eclipse.org/Eclipse_Plug-in_Development_FAQ#I.27m_using_third_party_jar_files_and_my_plug-in_is_not_working

PW