Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Can't use other bundle(Caused by: java.lang.ClassNotFoundException: )
Can't use other bundle [message #737803] Sat, 15 October 2011 13:21 Go to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi,

I created a bundle that contains the jdbc driver. Because I could not get it up and running I created a RCP Client application that uses this bundle and it works well. See the example below.

public class DBConnection {
	public static Connection getConnection() {
		Connection connection = null;
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
		}
		catch (java.lang.ClassNotFoundException e) {
			System.err.print("ClassNotFoundException: ");
			System.err.println(e.getMessage());
		}
		catch (InstantiationException e) {
			System.err.print("InstantiationException: ");
			e.printStackTrace();
		}
		catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		try {
			String connectionUrl = "jdbc:sqlserver://localhost:1433;database=MY_DB;";		
			connection = DriverManager.getConnection(connectionUrl, "user", "password");			
		}
		catch (SQLException ex) {
			System.err.println("SQLException: " + ex.getMessage());
		}
		return connection;
	}
}


When I add the same bundle to a Scout Server and configure the SQL Service (see below) it cannot find the class.

(First it could not able to find the bundle but solved that with the help of ivan.motsch)


public class MsSqlService extends AbstractSqlService implements IService {
  @Override
  protected String getConfiguredJdbcDriverName() {
    return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
  }

  @Override
  protected String getConfiguredJdbcMappingName() {
    return "jdbc:sqlserver://localhost:1433";
  }

  @Override
  protected String getConfiguredJdbcProperties() {
    return "database=MY_DB";
  }

  @Override
  protected String getConfiguredPassword() {
    return "password";
  }

  @Override
  protected String getConfiguredUsername() {
    return "user";
  }


So the question is, what is different in Scout that this does not work. Is it something with different class loaders ? or do I have to make some more configurations to make it work?

Regards Bertin
Re: Can't use other bundle [message #738103 is a reply to message #737803] Sat, 15 October 2011 21:16 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
Eclipse Scout is not different from any other Eclipse Application... (there are 2 applications: the client and the server). This means you need a little bit OSGi knowledge to come clear with Scout...

ClassNotFoundException is typical when you have problem with class loading... With OSGi, you need to forget everything you did to configure the classpath with java SE...

Two ideas:

1)
Where did you add the dependency to your Jar ? You should do it in the Runtimetime Tab of the Plugin.xml/Manifest editor of your Bundle.

2)
Before starting the application, did you clic: "Synchronize this configuration with the product's defining plug-in" in the .product file editor.

Re: Can't use other bundle [message #738653 is a reply to message #738103] Sun, 16 October 2011 14:58 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi,

what do you mean by this "You should do it in the Runtimetime Tab of the Plugin.xml/Manifest editor of your Bundle."

I can not find a location on the runtime tab where I can add a bundle. I added the bundle to the plug-in (see manifest) and on the product (see .MyServer-server-dev.product contents below) other wise it could not find the bundle.

But whatever I do and change in the plug-in or product configuration, it is never able to find the SQLServerDriver. It works perfect in a 'normal' RCP project. So what is different in the Scout server class loading?

Manifest
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MPXRid.server
Bundle-SymbolicName: MPXRid.server;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: MPXRid.server.Activator
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.core.runtime,
 MPXRid.shared,
 org.eclipse.scout.rt.server,
 com.microsoft.jdbc;bundle-version="1.0.0"
Export-Package: MPXRid.server,
 MPXRid.server.services.custom.security,
 MPXRid.server.services.common.sql,
 MPXRid.server.services.outline
Bundle-ClassPath: .
Import-Package: javax.servlet;version="2.4.0",
 javax.servlet.http;version="2.4.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6



MPXRid-server-dev.product :
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="MPXRid Server" id="MPXRid.server.product" application="MPXRid.server.app" useFeatures="false" includeLaunchers="true">

   <configIni use="default">
      <linux>/MPXRid.server/products/development/config.ini</linux>
      <macosx>/MPXRid.server/products/development/config.ini</macosx>
      <win32>/MPXRid.server/products/development/config.ini</win32>
   </configIni>

   <launcherArgs>
      <vmArgs>-Xms64m
-Xmx512m
-XX:MaxPermSize=256m</vmArgs>
   </launcherArgs>

   <windowImages/>

   <launcher>
      <solaris/>
      <win useIco="false">
         <bmp/>
      </win>
   </launcher>

   <vm>
   </vm>

   <plugins>
      <plugin id="MPXRid.server"/>
      <plugin id="MPXRid.shared"/>
      <plugin id="com.microsoft.jdbc"/>
      <plugin id="javax.servlet"/>
      <plugin id="org.apache.commons.codec"/>
      <plugin id="org.eclipse.core.contenttype"/>
      <plugin id="org.eclipse.core.jobs"/>
      <plugin id="org.eclipse.core.runtime"/>
      <plugin id="org.eclipse.core.runtime.compatibility.registry" fragment="true"/>
      <plugin id="org.eclipse.equinox.app"/>
      <plugin id="org.eclipse.equinox.common"/>
      <plugin id="org.eclipse.equinox.http.jetty"/>
      <plugin id="org.eclipse.equinox.http.registry"/>
      <plugin id="org.eclipse.equinox.http.servlet"/>
      <plugin id="org.eclipse.equinox.launcher"/>
      <plugin id="org.eclipse.equinox.launcher.win32.win32.x86" fragment="true"/>
      <plugin id="org.eclipse.equinox.preferences"/>
      <plugin id="org.eclipse.equinox.registry"/>
      <plugin id="org.eclipse.equinox.security"/>
      <plugin id="org.eclipse.equinox.security.win32.x86" fragment="true"/>
      <plugin id="org.eclipse.osgi"/>
      <plugin id="org.eclipse.osgi.services"/>
      <plugin id="org.eclipse.scout.commons"/>
      <plugin id="org.eclipse.scout.http.servletfilter"/>
      <plugin id="org.eclipse.scout.rt.jdbc.derby"/>
      <plugin id="org.eclipse.scout.rt.server"/>
      <plugin id="org.eclipse.scout.rt.shared"/>
      <plugin id="org.eclipse.scout.service"/>
      <plugin id="org.eclipse.update.configurator"/>
      <plugin id="org.mortbay.jetty.server"/>
      <plugin id="org.mortbay.jetty.util"/>
   </plugins>


</product>



console log
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
	at org.eclipse.scout.rt.server.services.common.jdbc.internal.pool.SqlConnectionBuilder.createJdbcConnection(SqlConnectionBuilder.java:35)
	at org.eclipse.scout.rt.server.services.common.jdbc.internal.pool.SqlConnectionPool.leaseConnection(SqlConnectionPool.java:102)
	at org.eclipse.scout.rt.server.services.common.jdbc.AbstractSqlService.leaseConnectionInternal(AbstractSqlService.java:609)
	... 61 more
Re: Can't use other bundle [message #738773 is a reply to message #738653] Sun, 16 October 2011 18:36 Go to previous messageGo to next message
Eclipse UserFriend
Simply add the following line the the MANIFEST.MF of 'com.microsoft.jdbc':
Eclipse-RegisterBuddy: org.eclipse.scout.rt.server


For more details see:
http://www.eclipse.org/forums/index.php/mv/msg/246503/738769/#msg_738769

-andreas


On 16.10.2011 16:58, bertin wrote:
> Hi,
>
> what do you mean by this "You should do it in the Runtimetime Tab of the
> Plugin.xml/Manifest editor of your Bundle."
> I can not find a location on the runtime tab where I can add a bundle. I
> added the bundle to the plug-in (see manifest) and on the product (see
> .MyServer-server-dev.product contents below) other wise it could not
> find the bundle.
>
> But whatever I do and change in the plug-in or product configuration, it
> is never able to find the SQLServerDriver. It works perfect in a
> 'normal' RCP project. So what is different in the Scout server class
> loading?
>
> Manifest
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: MPXRid.server
> Bundle-SymbolicName: MPXRid.server;singleton:=true
> Bundle-Version: 1.0.0.qualifier
> Bundle-Activator: MPXRid.server.Activator
> Bundle-ActivationPolicy: lazy
> Require-Bundle: org.eclipse.core.runtime,
> MPXRid.shared,
> org.eclipse.scout.rt.server,
> com.microsoft.jdbc;bundle-version="1.0.0"
> Export-Package: MPXRid.server,
> MPXRid.server.services.custom.security,
> MPXRid.server.services.common.sql,
> MPXRid.server.services.outline
> Bundle-ClassPath: .
> Import-Package: javax.servlet;version="2.4.0",
> javax.servlet.http;version="2.4.0"
> Bundle-RequiredExecutionEnvironment: JavaSE-1.6
>
>
>
> MPXRid-server-dev.product :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?pde version="3.5"?>
>
> <product name="MPXRid Server" id="MPXRid.server.product"
> application="MPXRid.server.app" useFeatures="false"
> includeLaunchers="true">
>
> <configIni use="default">
> <linux>/MPXRid.server/products/development/config.ini</linux>
> <macosx>/MPXRid.server/products/development/config.ini</macosx>
> <win32>/MPXRid.server/products/development/config.ini</win32>
> </configIni>
>
> <launcherArgs>
> <vmArgs>-Xms64m
> -Xmx512m
> -XX:MaxPermSize=256m</vmArgs>
> </launcherArgs>
>
> <windowImages/>
>
> <launcher>
> <solaris/>
> <win useIco="false">
> <bmp/>
> </win>
> </launcher>
>
> <vm>
> </vm>
>
> <plugins>
> <plugin id="MPXRid.server"/>
> <plugin id="MPXRid.shared"/>
> <plugin id="com.microsoft.jdbc"/>
> <plugin id="javax.servlet"/>
> <plugin id="org.apache.commons.codec"/>
> <plugin id="org.eclipse.core.contenttype"/>
> <plugin id="org.eclipse.core.jobs"/>
> <plugin id="org.eclipse.core.runtime"/>
> <plugin id="org.eclipse.core.runtime.compatibility.registry"
> fragment="true"/>
> <plugin id="org.eclipse.equinox.app"/>
> <plugin id="org.eclipse.equinox.common"/>
> <plugin id="org.eclipse.equinox.http.jetty"/>
> <plugin id="org.eclipse.equinox.http.registry"/>
> <plugin id="org.eclipse.equinox.http.servlet"/>
> <plugin id="org.eclipse.equinox.launcher"/>
> <plugin id="org.eclipse.equinox.launcher.win32.win32.x86" fragment="true"/>
> <plugin id="org.eclipse.equinox.preferences"/>
> <plugin id="org.eclipse.equinox.registry"/>
> <plugin id="org.eclipse.equinox.security"/>
> <plugin id="org.eclipse.equinox.security.win32.x86" fragment="true"/>
> <plugin id="org.eclipse.osgi"/>
> <plugin id="org.eclipse.osgi.services"/>
> <plugin id="org.eclipse.scout.commons"/>
> <plugin id="org.eclipse.scout.http.servletfilter"/>
> <plugin id="org.eclipse.scout.rt.jdbc.derby"/>
> <plugin id="org.eclipse.scout.rt.server"/>
> <plugin id="org.eclipse.scout.rt.shared"/>
> <plugin id="org.eclipse.scout.service"/>
> <plugin id="org.eclipse.update.configurator"/>
> <plugin id="org.mortbay.jetty.server"/>
> <plugin id="org.mortbay.jetty.util"/>
> </plugins>
>
>
> </product>
>
>
>
> console log
>
> Caused by: java.lang.ClassNotFoundException:
> com.microsoft.sqlserver.jdbc.SQLServerDriver
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
>
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
>
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
>
> at
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
>
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:169)
> at
> org.eclipse.scout.rt.server.services.common.jdbc.internal.pool.SqlConnectionBuilder.createJdbcConnection(SqlConnectionBuilder.java:35)
>
> at
> org.eclipse.scout.rt.server.services.common.jdbc.internal.pool.SqlConnectionPool.leaseConnection(SqlConnectionPool.java:102)
>
> at
> org.eclipse.scout.rt.server.services.common.jdbc.AbstractSqlService.leaseConnectionInternal(AbstractSqlService.java:609)
>
> ... 61 more
>
icon7.gif  Re: Can't use other bundle [message #738808 is a reply to message #738773] Sun, 16 October 2011 19:44 Go to previous message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Thanks,

Eclipse-RegisterBuddy: org.eclipse.scout.rt.server

works. You saved my weekend.

Regards Bertin
Previous Topic:Best practice for large BO's
Next Topic:Eclipse Scout RC4: MySql support?
Goto Forum:
  


Current Time: Thu Apr 25 09:08:20 GMT 2024

Powered by FUDForum. Page generated in 0.03239 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top