Dynamic Classloading

Hello all,
Could someone tell me a practical way to setup dynamic classloading in an EJB app? I'd like to set it up such that all of the shared codebase is deployed within the same ear with the EJB application. Is this practical or does dynamic classloading require the use of an external web-server? Right now I am trying to use the rmi.server.codebase system property via the %JAVA_OPTS% env. variable on appserver start-up to point to a servlet deployed in a .war my .ear. What is the practical approach? Thanks in advance.
Cliff

Thank you crackers,
You've cleared alot for me. So if I follow what you're saying then my problem boils down to how my client talks to the server. And the principles of EJB state that the communication details are left to the vendor. All I have to do then is get my home interface via JNDI. This assumes of course that the stubs are available on the client.
Now don't get me wrong here, I'm not trying to debate the advantages of EJB. I'm just trying to illustrate my dillemma and find a plausible solution. In my scenario I'm not really all that concerned with the transport layer (well I am concerned with the leaky abstractions therein but that's another story). I'm primarily concerned with versioning issues. I cannot maintain classes installed on the client as they could potentially fall out of date with the server. I need a dynamic classloading mechanism, which I thought would be provided with EJB as it is with RMI. I just naturally assumed it would be since EJB is typically (though not always, as you point out) layered always RMI. If you're saying that there is no such facility then I will have to find an alternative solution for my problem. You see I have no choice and I must concern myself with the underworkings of EJB as there are leaky abstractions within the technology. While it is a powerful technology it does not solve all of my problems. Also, I need to fill these holes in a vendor neutral way.
Cliff

Similar Messages

  • Dynamic ClassLoader

    Hi there,
    i am trying to program a dynamic classloader in Abap. by now i came this far:
    DATA classname TYPE string VALUE 'ZCL_TEST'.
    DATA dref TYPE REF TO data.
    DATA type_descr TYPE REF TO cl_abap_typedescr.
    FIELD-SYMBOLS <ref> TYPE ANY.
    type_descr = cl_abap_typedescr=>describe_by_name( p_name = classname ).
    classname = type_descr->absolute_name.
    CREATE DATA dref TYPE REF TO (classname).
    ASSIGN dref->* TO <ref>.
    CREATE OBJECT <ref> TYPE (classname).
    dref->to_string( ). -----> ERROR
    The ClassLoading itselfs works perfectly, but now i don't know how to call a method of that class... Can't beliieve that i can instantiate a Class but not call a method?!?
    So has someone done it already and can point me the right way?
    Thanks
    Mathias

    I don't know what would be the use of creating the object with REF TO DATA and than assign it back to the variable REF TO OBJECT to be able to access the data.
    CREATE DATA dref TYPE REF TO
               ('\program=kellerh_test\interface=i1').
    Here you are creating the TYPE at runtime which is type referent to the Interface. You get the object reference to the Field-Symbol. But Since field-symbol is not allowing to access the attributes, we need to cast that into the variable TYPE REF TO OBJECT.
    Check this code:
    REPORT  ztest_np_1.
    INTERFACE i1.
      DATA: w_num TYPE i.
    ENDINTERFACE.                    "i1
    CLASS c1 DEFINITION.
      PUBLIC SECTION.
        INTERFACES i1.
    ENDCLASS.                    "c1 DEFINITION
    DATA dref TYPE REF TO data.
    FIELD-SYMBOLS <ref> TYPE any.
    CREATE DATA dref TYPE REF TO
               ('\program=ZTEST_NP_1\interface=i1').
    ASSIGN dref->* TO <ref>.
    CREATE OBJECT <ref> TYPE c1.
    FIELD-SYMBOLS <attr> TYPE ANY.
    DATA: lo_obj TYPE REF TO object.
    lo_obj ?= <ref>.
    ASSIGN lo_obj->('I1~W_NUM') TO <attr>.
    <attr> = 10.
    WRITE: 'Test'.
    Regards,
    Naimesh Patel

  • Dynamic classloading without default constructor

    Just wondering if anyone has done dynamic classloading using a constructor other than the default. I know that newInstance() calls the default constructor. But how would you do it without that? Thanks for the help.

    If you know that there is a constructor that takes,
    for example, a single String argument you can use
    something like this:
    Class clazz = ...; // class to instantiate
    String stringArg = ...; // argument to pass to constructor
    Constructor c = clazz.getConstructor( new Class[] { String.class } );
    Object value = c.newInstance( new Object[] { stringArg > } );
    And even better, when JDK 1.5 is released, you'll be able to write:
        Class clazz = ...;
        String stringArg = ...;
        Constructor c = clazz.getConstructor(String.class);
        Object value = c.newInstance(stringArg);Geoff

  • Dynamic classloading and incompatibleclasschangeerror

    I have different versions of my applications like v1 v2 v3 and my current version is v4.
    In my case, v4 might need to talk to v3, v2 or v1. To achevie that I need that same versions of classes from the respective versions of the applications i.e. I will make jars like v3.jar, v2.jar and v1.jar which will be loaded dynamically using my own custom class loaders. When v4 trying to access v3 it uses the classes using the classloader which loaded v3.jar
    v4 contacts v3, v2, v1 through RMI.
    Now the problem is when v4 is calling a remote method of v3 I am getting IncompatibleClassChangeError
    I tried to recompile all the required classes in v3 and created a new v3.jar and I have loaded the same dynamically in v4. I also recompiled all the classes of v4, but still the result is same.
    Both v3 classes and v4 classes are compiled using the same JRE version.
    Can somebody help me to figure out what could be the issue.
    Thanks

    If you know that there is a constructor that takes,
    for example, a single String argument you can use
    something like this:
    Class clazz = ...; // class to instantiate
    String stringArg = ...; // argument to pass to constructor
    Constructor c = clazz.getConstructor( new Class[] { String.class } );
    Object value = c.newInstance( new Object[] { stringArg > } );
    And even better, when JDK 1.5 is released, you'll be able to write:
        Class clazz = ...;
        String stringArg = ...;
        Constructor c = clazz.getConstructor(String.class);
        Object value = c.newInstance(stringArg);Geoff

  • RMI dynamic classloading problems

    I wanted to know if you could help me answer this particular case,
    which i still haven't been able to solve in days:
    1>RMI Client and Server are on different hosts.
    2>the Client makes a RMI method call to a Server who has to execute
    dynamically a particular classfile specified by the client itself and
    return the result to the client
    PROBLEM IS:
    at the beginning only the client has the classfile to be executed by
    server and needs to transfer him the information in order to have its
    RMI method executed,and no ohter protocols except for RMI are
    allowed.
    QUESTION IS:
    how could i solve this case with the use of codebases and
    URLClassLoader Objects?
    hoping i've clearly made the point,thanXalot
    nicholas

    The client can set its own codebase. The client class that the server will call needs to implement an interface the server knows. Then the client will pass this object to the server, and the server will make its call on that object. Since this object is not exported it will be serialized to the server, and the call will run on the server.
    Quite insecure. But it should work just that simply I do believe.
    You do know how to use codebase?

  • Dynamic ClassLoader - feasability question

    Problem: need to be able to 'hot-replace' a class definition at runtime
    Particulars:
    A method of this class popuplates a hash map with 'key-<anon.class>' pairs, ie:
    public void initTransformerMap() {
       xMap.put("Color", new Transformer() {
           public Object transform(Object in) {
               return ((Car)in).getColor();
       xMap.put("Engine Capacity", new Transformer() {
           public Object transform(Object in) {
               return ((Car)in).getEngine().getCapacity().toString() + " cc";
    }I need to be able to define new map entries and change existing ones (including the definition of the anon. classes) and load the class in.
    Any sensible suggestions are welcome

    You can run the java compiler from your program to compile .java files to class files and then load and use the new classes.
    You can't replace a class definition once it is loaded. But if you can load different classes with the same name with different classloaders. Which might look like replacing one class with the other.
    search the forum/web and you'll find plenty of examples
    regards
    Spieler

  • Serialization with dynamic classloader

    i have the following problem:
    i load a serialized object from a file. This object's classes are are in a folder , witch is not in CLASSPATH, and so the classes are not loaded when i try to read objects from the file.
    I loaded this classes with my class loader , but i still get an error when a read the object from the file.
    I lookt all day for an example, so any help is apreciated.
    Thx

    As a guess you need to create your own version of ObjectInputStream and overload some of the methods in it - like resolveClass()
    There are a number of threads that are returned using the search string "resolveClass ObjectInputStream"
    Loking at a couple I found this...
    http://forum.java.sun.com/thread.jspa?forumID=4&threadID=468339

  • Classloading within Webstart plus static classes

    Hi folks!
    I've a big problem in a software project in "migrating" a normal client-server-RMI-SWT-application to be 100% webstart compatible.
    Everything works really fine except for dynamic classloading on demand.
    The system currently is packaged in some jars.
    Depending on the mask shown to the screen, the system looks for a "customize" class inside the resources. If it finds one, it loads and then does a "defineClass" and then calls a method via the "invoke" mechanism.
    The classes are kind of standardized.
    The problem is, that the "refering" classes from the - let's say - main application are mostly static.
    The called class then tries to call the "namespace" of these classes but only get's null objects - no matter what object it was.
    Run as a normal application - the whole system is working perfectly.
    So as a "big picture", I have the following construct:
    calling Client-Application + Classloader, using a static class for saving object data.
    defining content of one of these static classes:
    DemoObject.setFoobar("Hello world");
    ClassLoader .....
    getResourceAsStream("com/foobar/demo/customizeLogic.class");
    defineClass(byte[] blablablabla,....)
    findMethod.....
    myMethod.invoke(....)inside the dynamic loaded customizeLogic class we do the following
    String demo = DemoObject.getFoobar();
    // this results now into NULL
    // even the ClassLoader is manually loading all java.* plus all other classes because it seems to have a securitymechanism not to share the class-space.I already tried to set the classloader to all variants like SystemClassLoader, ContextClassLoader etc.
    -- but, none worked. I cannot share the same ClassLoader-Resources with the main and "fixed" application... :-(
    Does anyone have a clue or needs more information? I can post some sourcecode also.
    Thorsten

    Hi folks!
    For the most of our problems we're now doing it as "keep it simple".
    I'm just making a Class.forName - "Loading" which works good for alle the classes out of the jars.
    PLUS the setSecurityManager tag - yup.
    During the last weeks I wasn't able to reply because the project ate too much time.
    We'll split the classloading into two or more or less 3-4 parts. One is for the WEBSTART - Edition and one for "normal Client" version. The webstart version we'll split for loading classes vs. loading "normal" resources out of the jars... this will give us flexibility while being able to solve all our problems for now...
    Regards,
    Thorsten

  • Jsr 82 and portability

    Hello,
    I'm currently writing a MIDP application which uses some
    optional packages, namely JSR 75 (FileConnection API) and
    JSR 82 (Bluetooth API).
    I'm aware you can test the presence of those APIs with
    <code>
    System.getProperty("microedition.io.file.FileConnection.version")
    </code>
    and since there is no System property to indicate JSR 82 presence
    you can try to load a class from that package:
    <code>
    try{Class c = Class.forName("javax.bluetooth.DiscoveryAgent")} catch (ClassNotFoundException e) {}
    </code>
    Now that I know that JSR 82 is present, I could use a btspp:// connection to communicate with a server. If JSR 82 not present,
    then I would use a socket:// connection.
    But my code fails, if JSR 82 is not present. It's somewhat strange --
    I can use the LocalDevice and DiscoveryAgent classes in my code
    when I make sure they are not reached if JSR 82 not present (see code below). I Think this is only possible, because the KVM itself doesn't verify if all classes as this is done in a preverification process. So using these classes is not a clean solution, but I have no other idea right now.
    <code>
    if (jsr82present) {
         //do device discovery
         LocalDevice local = LocalDevice.getLocalDevice();
         local.setDiscoverable(DiscoveryAgent.GIAC);
         DiscoveryAgent agent = local.getDiscoveryAgent();
         //fails in the next line, although this code is
         //never reached when jsr 82 not present
         agent.startInquiry(DiscoveryAgent.GIAC, new DiscoveryListener(){
              //interface methods here
    } else {
         //establish socket connection
    </code>
    My code fails as soon as I use "new" to instantiate a DiscoveryListener (which is also part of JSR 82) -- even if the instance will never be created, since a device with no JSR 82 support would never reach this code. See my problem now?
    Does this mean I have to write two different applications, one for bluetooth communication and the other one for sockets?
    I've tried to get around this with dynamic classloading, but didn't work either:
    <code>
    Class c = Class.forName("mypckg.MyDiscoverListener");
    c.newInstance(); //<-- fails here
    </code>
    Has anyone an idea how to write one application for different devices with different optional packages installed, which uses all functionality
    the device offers through it's optional packages?
    Or is it just impossible?
    Regards,
    Torben

    try this link
    http://www.jcp.org/aboutJava/communityprocess/final/jsr082/

  • Quirk of wls 4.5.1 startup..

    <HELP ME>
    I have no understanding as to why, but it seems that the dynamic classloader
    thingy will not function unless you begin the process from <installDir>.
    Because of this the batch file to start the hotDeploy version must be in
    your <installDir> and all references to classes found stemming from the
    <installDir> must be indicated using .\theClass
    I would love somebody to explain why this is so.
    In other words:
    if you do this:
    set WLS_INSTALL_DIR=d:\weblogic
    set JAVACLASSPATH=%WLS_INSTALL_DIR%\classes\boot;.....etc etc
    you throw an Exception in Thread Main class not found Exception
    javax.naming.blah blah
    if instead you start your .bat file from d:\weblogic and do this:
    set JAVACLASSPATH=.\classes\boot;...etc etc
    everything works great.
    </HELP ME>

    Great. I'm glad that worked out for you.
    The will ask the documentation team to place a note regarding this.
    Thanks,
    Michael
    Michael Girdley
    Product Manager, WebLogic Server & Express
    BEA Systems Inc
    Owen Taylor <[email protected]> wrote in message
    news:8g2odh$hg7$[email protected]..
    You are so right! - kind of. It turns out you must start your .bat file
    from a directory which contains a global weblogic.properties file and you
    must specify the path to the weblogic.policy file. If you do these things
    you can use any arbitrary %VARIABLES% that you like with full success.
    Thankyou.
    Michael Girdley <[email protected]> wrote in message
    news:8fflt5$36n$[email protected]..
    I believe that you were simply witnessing an artifact of the relativepaths
    that we used in the start script. If you were to give full paths there,
    I
    think that you would be fine.
    Thanks,
    Michael
    Michael Girdley
    Product Manager, WebLogic Server & Express
    BEA Systems Inc
    Owen Taylor <[email protected]> wrote in message
    news:8fd6go$oe9$[email protected]..
    <HELP ME>
    I have no understanding as to why, but it seems that the dynamicclassloader
    thingy will not function unless you begin the process from
    <installDir>.
    Because of this the batch file to start the hotDeploy version must bein
    your <installDir> and all references to classes found stemming fromthe
    <installDir> must be indicated using .\theClass
    I would love somebody to explain why this is so.
    In other words:
    if you do this:
    set WLS_INSTALL_DIR=d:\weblogic
    set JAVACLASSPATH=%WLS_INSTALL_DIR%\classes\boot;.....etc etc
    you throw an Exception in Thread Main class not found Exception
    javax.naming.blah blah
    if instead you start your .bat file from d:\weblogic and do this:
    set JAVACLASSPATH=.\classes\boot;...etc etc
    everything works great.
    </HELP ME>

  • How to clear old class files cached in JVM

    JVM stores old class files in its cache even after the corresponding files have been deleted from the database. This causes a conflict if a new file is saved with the same name as one that was deleted earlier causing old data to be fetched and not the new one.
    am using the following line of code to load the class file :
    Class.forName(className, false, this.getClass().getClassLoader())
    please help
    Thanks - N

    Why are you trying to do that?
    Dynamic Classloading(reloading) has a meaing only on "application container" like WAS.
    Not appropriate for normal applcation.
    Focus on enhancing your application logic and algorithm rather than wasting your brain on difficult and meaningless things. Applying some flexible design patterns wouldn't suffice?
    Anyway, Sun provides wonderful and simple custom classloader sample.
    http://java.sun.com/developer/onlineTraining/Security/Fundamentals/magercises/ClassLoader/help.html
    Anayzing tomcat source(which is downloadable) is another approach.
    Edited by: Dion_Cho on Nov 26, 2007 5:18 PM
    Typo...

  • WLS with Cocoon

    Has anyone tried using Apache's Cocoon for managing web publishing? I've
    has a go with Xalan and Xerces, and been pleased with these to date. I've
    now come across Apache's Cocoon, and would be interested to here the
    opinions of anyone who has used it already.
    Mark.

    I also managed to get cocoon and weblogic 451 working without too much
    difficulty.
    However I have't been able to suss out the mechanism for passing a default
    file to the cocoon servlet.
    Anybody know what to do?
    Humphrey Sheil <[email protected]> wrote in message
    news:[email protected]...
    I got Cocoon 1.7.4 working with weblogic 5.1 very easily (apart from one
    major issue which I'll detail and gripe about below ;-)).
    I used the instructions posted on the Cocoon list by Philip Aston (which
    I've included below) which worked but one change was required.
    I got a problem (about 50% of the time) where weblogic would fail todeploy
    my cocoon war and also complain about another process listening on ports
    7001 / 7002 which simply wasn't true. Turns out that if weblogic isunable
    to parse the web.xml that comes with cocoon, I had to replace it with an
    example taken from the weblogic examples directory (with the relevant
    information included). The way weblogic deals with this - cascading the
    error in deploying to affect the port listening is not good.
    Once I got this working, I hooked up security etc. in about 10 minutesusing
    the servlet 2.2 form-based authentication and am generally very happy with
    the weblogic-cocoon integration.
    Here are the posted instructions and I'm also attaching my web.xml file asa
    reference. I didn't have any problems getting XSP to work (although I'mnot
    using it at all - just hitting the samples provided). Even given thepoints
    Philip makes below about losing hot deploy abilities, your EJBs should
    deploy fine with this turned off.
    Regards,
    Humphrey
    Philip Aston wrote:
    I've been playing with using Cocoon 1.7.4 in conjunction with BEA
    WebLogic Server 5.1. (Stefano and folks, feel free to add any or all
    of this to the installation guide. You might also like to add a
    success report for MS NT 4.0 SP4, BEA WebLogic Server 5.1 SP3, JDK
    1.2.2.)
    WLS 5.1 implements Servlet 2.2. so it plugs in easily. Here's a quick
    recipe:
    - Add the xerces, xalan, fop, servlet, and cocoon JAR files (from the
    distribution) to your CLASSPATH. (See below). If you're using Java
    2, you should also add the tools.jar file from the JDK distribution
    to your CLASSPATH.
    - Create a new subdirectory tree of your WLS run time directory
    "cocoonwar/WEB-INF" and copy the default web.xml file (from the
    src directory of the distribution) there.
    - Copy the cocoon.properties from the conf directory of the
    distribution to cocoonwar/WEB-INF and updated the web.xml file to
    refer to it.
    - Copy the samples directory from the distribution to cocoonwar
    - Map the web application into the WLS URI name space by adding the
    following line to your weblogic.properties file:
    weblogic.httpd.webApp.cocoon=cocoonwar
    Start WLS, point your browser at
    "http://localhost:7001/cocoon/samples/index.xml" and away you go.
    Classpaths and XSP:
    To support hot deployment of EJB's and Servlets, WebLogic Server
    uses its own class loader with its own classpath (the "WebLogic
    classpath"). Normally you'd put all the WebLogic Server container
    code, JDBC drivers, etc. in your Java CLASSPATH (so that WebLogic
    Server can start up) and add all your application code (stuff that
    needs to be able to be redeployable) to the WebLogic classpath.
    Cocoon is effectively "container" code, and the XSP processor uses
    dynamic classloading which only understands the Java CLASSPATH, so
    you should put all of the Cocoon jars in CLASSPATH.
    The big problem with this is that you can't use any code that loads
    from the WebLogic classpath within XSP's. This includes all of the
    WebLogic API, so is a PITA. To overcome this, either the way Cocoon
    loads classes needs to be modified (Stefano, is this easy?), or the
    WebLogic Server class loader needs to be disabled (in which case you
    have to be willing to live without hot redeployment).
    To disable the WebLogic class loader, put your application classes,
    the Cocoon jars and all of the WebLogic Server stuff into the Java
    CLASSPATH add -Dweblogic.system.disableWeblogicClassPath=true to the
    Java command at the end of you WebLogic start script.
    - Phil
    This is not an official BEA response. Please do not send me unrelated
    WebLogic support questions - I am unable to answer them. Instead
    please use the BEA developer newsgroups - see
    http://developer.bea.com, or contact BEA support.
    Philip Aston - Senior Consultant
    BEA Professional Services (Northern Europe)
    "Bob" <[email protected]> wrote in message
    news:[email protected]...
    I have been trying to get Cocoon working with WL. So far it has been a
    lot
    of trouble. I am mostly interested in getting XSP to work. The firstthing
    you need to do is usethe -Dweblogic.system.disableWeblogicClassPath=true
    command to turn off dynamic class loading. The problem I am now havingis
    that some of my EJBs won't deploy.
    If you don't want XSP Cocoon works well.
    -Bob
    Mark Bower <[email protected]> wrote in message
    news:[email protected]...
    Has anyone tried using Apache's Cocoon for managing web publishing?
    I've
    has a go with Xalan and Xerces, and been pleased with these to date.I've
    now come across Apache's Cocoon, and would be interested to here the
    opinions of anyone who has used it already.
    Mark.

  • RMI classpath

    Hello
    I'm trying to start RMI application in a dynamic-classloading environment.
    More precisely: Application load additional classes from non classpath libraries (which include remote interfaces, implementations and generated stubs) thrugh custom URLClassLoader. Then it attempts to bind one of loaded classes to RMI registry via Naming.bind()... But it doesn't work. It crashes with ClassNotFoundExcetpion, indicating that it can't find remote interface for binding class.
    Is it any way to bind new classes to RMI at runtime?
    Thank you
    Alexander Godin

    If I understand your problem correctly, I think what you need to do is set your -Djava.rmi.server.codebase property on the JVM which is doing the exporting.
    Theres a good guide to this here:
    http://java.sun.com/j2se/1.4.2/docs/guide/rmi/codebase.html

  • InvalidClassException, serialVersionUID

    i am performing dynamic classloading over network (almost).
    however, my final(?) error is such:
    java.io.InvalidClassException.... local class incompatible: stream classdesc serialVersionUID = -17289354839854, local class serialVersionUID = 987654321
    in the class that is being loaded, i "lock-down"(?) the serialVersionUID with:
    static final long serialVersionUID = 987654321;what are some things for me to look at?
    on the client that is trying to load the class, there is no copy of the target class file.
    there really is only one physical class file and it is on the server.
    and it was compiled with serialVersionUID = 987654321.
    and it is marked as final_ .
    where is that crazy serialVersionUID = -17289354839854 coming from?
    thoughts and ideas appreciated.
    Edited by: kappa9h on Nov 25, 2007 6:15 AM

    i am doing a byte-by-byte copy of a class file from the server to the remote ClassLoader
    over a Socket stream. so how is the serial ID changing?
    i read the class file into a byte[] and stream is over the Socket.
    and on the other end of the Socket, the byte[] is exactly the
    same size. so, i am not dropping bytes or re-ordered (its tcp). so i don't know.
    public class MyClassLoader extends ClassLoader {
      public Class findClass(String name) {
        byte[] buf = loadClassData(name);
        return(defineClass(name, buf, 0, buf.length));
      private byte[] loadClassData(String name) {
        Socket sok = new Socket("192.168.0.3", 8877);
        InputStream in = sok.getInputStream();
        byte[] buf = new byte[1048];  // <-- now i cheat and hardwire the correct size
        in.read(buf);
        return(buf);
    }on the other end, server "192.168.0.3", i have a
    ServerSocket listening on *8877.*
    when it is connected to, i read: *"/tmp/myClass.class"* into a byte[]
    and send it over the Socket.

  • Dyn-loading with newInstance() vs. static ref

    Hello.
    Here is code that does what I want:
    Class.forName("com.mysql.jdbc.Driver").newInstance();  // load mysql/jdbc driver
    Connection conn = DriverManager.getConnection("jdbc:mysql://ebi:3306/jlpt", "root", "pwd");
    // conn is good-to-go
    ....Regarding this line:
    Class.forName("com.mysql.jdbc.Driver").newInstance();as the returned value is ignored, this is, except for the classloading, a no-op?
    Now, my understanding, is that any reference to a class triggers the loading of the class? If so, a static reference to "com.mysql.jdbc.Driver" should also load the jdbc/mysql driver class. However, this code fails with a "driver not found" exception:
    String whatever = com.mysql.jdbc.Driver.DBNAME_PROPERTY_KEY;  // why not load mysql/jdbc driver?
    Connection conn = DriverManager.getConnection("jdbc:mysql://ebi:3306/jlpt", "root", "pwd");
    // java.sql.SQLException: No suitable driver found for jdbc:mysql://ebi:3306/jlpt
    //   at java.sql.DriverManager.getConnection(DriverManager.java:602)
    //   at java.sql.DriverManager.getConnection(DriverManager.java:185)
    ....Here is how I tested that a static reference loads a class:
    public class Main {
        public static void main(String[] args) {
            System.out.println("start");
            int q = ClassA.i;  // toggle this by commenting out / in
            System.out.println("end");
    public class ClassA {
        static {
            System.out.println("ClassA just loaded.");
        static int i = 1;
    }Dynamic classloading is difficult for me, and I hope I can learn from this. Thanks.
    Edited by: rerf on Jul 9, 2010 9:05 AM

    jverd wrote:
    rerf wrote:
    Hello.
    Here is code that does what I want:
    Class.forName("com.mysql.jdbc.Driver").newInstance();  // load mysql/jdbc driver
    Connection conn = DriverManager.getConnection("jdbc:mysql://ebi:3306/jlpt", "root", "pwd");
    // conn is good-to-go
    ....Regarding this line:
    Class.forName("com.mysql.jdbc.Driver").newInstance();as the returned value is ignored, this is, except for the classloading, a no-op?JDBC drivers are supposed to have a static initializer block so that when the class is loaded, it registers itself with DriverManager. That's why we do the explicit Class.forName(). Note that the newInstance() is unnecessary.
    Now, my understanding, is that any reference to a class triggers the loading of the class? If so, a static reference to "com.mysql.jdbc.Driver" should also load the jdbc/mysql driver class. However, this code fails with a "driver not found" exception:
    String whatever = com.mysql.jdbc.Driver.DBNAME_PROPERTY_KEY;  // why not load mysql/jdbc driver?
    Connection conn = DriverManager.getConnection("jdbc:mysql://hiroo:3306/jlpt", "root", "rpp");
    // java.sql.SQLException: No suitable driver found for jdbc:mysql://ebi:3306/jlpt
    //   at java.sql.DriverManager.getConnection(DriverManager.java:602)
    //   at java.sql.DriverManager.getConnection(DriverManager.java:185)
    I don't know. Just as a guess, it might be that the "whatever" line is getting optimized away since you never use "whatever." Try printing it out and see if that changes things. I would have expected that to cause the class to load as well.this runs ok:
    String whatever = com.mysql.jdbc.Driver.DBNAME_PROPERTY_KEY;
    // Connection conn = DriverManager.getConnection("jdbc:mysql://ebi:3306/jlpt", "root", "pwd");
    System.out.println("whatever --> " + whatever);
    ....this still fails with: "java.sql.SQLException: No suitable driver found"
    String whatever = com.mysql.jdbc.Driver.DBNAME_PROPERTY_KEY;
    Connection conn = DriverManager.getConnection("jdbc:mysql://ebi:3306/jlpt", "root", "pwd");
    System.out.println("whatever --> " + whatever);
    // java.sql.SQLException: No suitable driver found for jdbc:mysql://ebi:3306/jlpt
    //   at java.sql.DriverManager.getConnection(DriverManager.java:602)
    //   at java.sql.DriverManager.getConnection(DriverManager.java:185)
    //   at kdata.DenJ.xtract(DenJ.java:85)
    //   at kdata.Main.main(Main.java:13)
    .... Anyway, I am ok. Thanks for your time.

Maybe you are looking for

  • How Do I Delete My Backup Files off of my Hard Drive?

    I finally figured out what was eating up all of my hard drive! Check this out: 43 Gigs in Backup! Now I can't figure where these files are located and how to delete all these files? I have a LaCie external drive I just purchased and would like to beg

  • Java 7 release 25 will not work on Firefox 22 -- tried all the "fixes" and it works in IE and Chrome. What now?

    The newest release of Java (7.0.250) simply will not run on Firefox 22. I have tried all the "fixes" posted on the Mozilla site -- enabled in both the browser and the Java control panel. The new release of Java works just fine in IE and Chrome.

  • Minimized messages do not appear under the Window menu

    If I minimize a few messages (yellow button) in Mail, then quit Mail and reopen Mail, the minimized messages don't appear under the Window menu. The only way to retrieve them is to go into Expose one at a time and click on them. This seems like a bug

  • PO not created in Backend

    HI, My SRM Quality gets re-freshed and i am on ECS scenario, i change all the ALE settings and now i am able to create a Shopping cart but when PO is created in my SRM system it is not replicated in ECC quality and i can see my status of the Purchase

  • Will i need to have streaming server

    Hello and happy saturday, I have not used robohelp before, and thought I would download the trial. but just a quick question. when I create a robohelp application, do I need to put it on a streaming server, I am confused as to what to do when I have