Java class libraries and class paths

I'm using NetBeans IDE 6
I'm trying to make a class library (which is started from another application).
This is supposed to connect to a SQL 2005 database by first registering the SQLServerDriver from the sqljdbc.jar library.
I've tried it in an Application with a main class and it runs fine. But when I move the built classes to the folder I want them to run from, I get a ClassNotFound exception for the ServerDriver when run.
I'm assuming it is a problem with the classpath after I make the move, is there anything special I need to do to keep the classpath intact so it can find the driver?
Sorry if it's too vague, I can try to clarify things if needed.

See this NetBeans tutorial:
http://www.netbeans.org/kb/articles/javase-deploy.html
These forums provide support for Java programming, not NetBeans (or any other IDE.)
This question should have been posted to the NB site mailing list.

Similar Messages

  • Windows classpath vs java.class.path error in QuickTime based applet

    Hello
    I've spent days reading and searching the internet, and I'm still stumped why some Windows installations are not able to run my QuickTime for Java based applet even though QuickTime is installed (the specific error is: java.lang.NoClassDefFoundError: quicktime/QTException). I have some additional details and a question that might spur someone to an insightful nudge.
    On a Windows system that fails:
    echo %classpath%
    .;C:\Program Files\QuickTime\QTSystem\QTJava.zipWhich is where QTJava.zip is found on the (faulty?) system, but java.class.path is just:
    java.class.path = C:\PROGRA~1\Java\jre6\classes
    Of the dumped system properties, only java.library.path makes any mention of the QTSystem folder (or any other QT or QuickTime related items).
    java.library.path = C:\Program Files\Safari;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\PROGRA~1\Java\jre6\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\QuickTime\QTSystem\
    I ran across one thread (elsewhere) where the user was having problems with loading some classes from a complex JAR environment, and a solution was to write a custom class loader. After doing so, the user got the same error "java.lang.NoClassDefFoundError: quicktime/QTException" that was resolved by extending the custom class loader to include .zip files. I'm not sure if the solution is relevant, or if he simply broke something in his custom class loader that would have worked otherwise. I've not written a custom class loader and not sure where to begin, so before I ventured down that path I was hoping someone might shed some light as to if this is a dead end or potential solution. This is a signed applet (QuickTime now requires it, even if you are only playing files of the same server) and it does work on several Windows machines and all tested Macs.
    Thank you,
    Deron
    output to Java Console with level 5 tracing enabled
    basic: Joining applet thread ...
    basic: Joined applet thread ...
    basic: Referencing classloader: sun.plugin.ClassLoaderInfo@750159, refcount=2
    basic: Finding information ...
    basic: Releasing classloader: sun.plugin.ClassLoaderInfo@750159, refcount=1
    basic: Done ...
    basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@3a9bba
    basic: Loading applet ...
    basic: Initializing applet ...
    basic: Starting applet ...
    basic: completed perf rollup
    network: Cache entry not found [url: http://www.equushd.com/quicktime/QTException.class, version: null]
    network: Connecting http://www.equushd.com/quicktime/QTException.class with proxy=DIRECT
    network: Connecting socket://www.equushd.com:80 with proxy=DIRECT
    java.lang.NoClassDefFoundError: quicktime/QTException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: quicktime.QTException
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 10 more
    basic: Exception: java.lang.NoClassDefFoundError: quicktime/QTException
    Ignored exception: java.lang.NoClassDefFoundError: quicktime/QTException

    Something is wrong with the library.
    Staring at java code will not help you figure that out.
    Maybe it isn't intended to be loaded in java but instead it loads java itself?
    If not then write a C/C++ basic app that links that dll in and see if you can at least get it to start.

  • System.setProperty("java.class.path", cp)

    hello,
    I have written a little program that is supposed to set the CLASSPATH var in a instance of
    bash ... not set it permantly. Anyway, after running the program when i run,
    echo $CLASSPATH
    none of the changes i make with the program are there.... why is this?
    thanks,
    jd
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import layout.TableLayout;
    import com.incors.plaf.kunststoff.KunststoffLookAndFeel;
    public class JPathGui extends JFrame{
         JButton cpSubmit;
         JButton cpClear;
         JButton qaSubmit;
         JButton qaClear;
         JTextField cptf;
         JTextField qatf;
         public JPathGui(){
              super("JPATH ver .001");
              try {
                        UIManager.setLookAndFeel(new KunststoffLookAndFeel());
                 } catch (Exception ignored) {}
              addWindowListener(new WindowAdapter()
                     public void windowClosing(WindowEvent e){
                    System.exit(0);
              JPanel mainPanel = new JPanel();
              mainPanel.setPreferredSize(new java.awt.Dimension(800,230));
              double[][] size = {{10,780,10},{20,30,5,30,10,20,30,5,30}};
            TableLayout layout = new TableLayout(size);
            mainPanel.setLayout(layout);
              myGetClassPath(mainPanel);
              myQuickAdd(mainPanel);          
              getContentPane().add(mainPanel);
              pack();
            setSize(820,230);
            setVisible(true);
         public void myGetClassPath(JPanel mainPanel){
              JLabel cpl = new JLabel("ClassPath");
              JPath jp = new JPath();     
              cptf = new JTextField(jp.getClassPath());
              cptf.setFont( new Font("Monospaced", Font.PLAIN, 10) );
              cptf.setPreferredSize(new java.awt.Dimension(780,50));
              mainPanel.add(cpl, "1,0");
              mainPanel.add(cptf, "1,1");
              JPanel cpActionPanel = new JPanel();
              cpActionPanel.setPreferredSize(new java.awt.Dimension(780,50));
              double[][] size1 = {{570,100,100,30},{30}};
            TableLayout layout1 = new TableLayout(size1);
            cpActionPanel.setLayout(layout1);
              cpSubmit = new JButton("Submit");
              cpClear = new JButton("Clear");
              cpSubmit.setSize(40,20);
              cpClear.setSize(40,20);
              cpSubmit.addMouseListener(new command_listner());
              cpClear.addMouseListener(new command_listner());
              cpActionPanel.add(cpSubmit , "1,0");
              cpActionPanel.add(cpClear, "2,0");
              mainPanel.add(cpActionPanel, "1,3");
         public void updateCPTF(){
              JPath jp = new JPath();     
              cptf.setText(jp.getClassPath());
         public void myQuickAdd(JPanel mainPanel){
              JLabel qal = new JLabel("QuickAdd");
              qatf = new JTextField();
              qatf.setFont( new Font("Monospaced", Font.PLAIN, 10) );
              qatf.setPreferredSize(new java.awt.Dimension(780,50));
              mainPanel.add(qal, "1,5");
              mainPanel.add(qatf, "1,6");
              JPanel qaActionPanel = new JPanel();
              qaActionPanel.setPreferredSize(new java.awt.Dimension(780,50));
              double[][] size2 = {{570,100,100,30},{30}};
            TableLayout layout2 = new TableLayout(size2);
            qaActionPanel.setLayout(layout2);
              qaSubmit = new JButton("Submit");
              qaClear = new JButton("Clear");
              qaSubmit.setSize(40,20);
              qaClear.setSize(40,20);
              qaSubmit.addMouseListener(new command_listner());
              qaClear.addMouseListener(new command_listner());
              qaActionPanel.add(qaSubmit , "1,0");
              qaActionPanel.add(qaClear, "2,0");
              mainPanel.add(qaActionPanel, "1,8");
         public class command_listner extends MouseAdapter{
                 public void mouseClicked(java.awt.event.MouseEvent evt){
                       Object source = evt.getSource();
                   //cpSubmit
                   if(source == cpSubmit){
                        JPath jp = new JPath();
                        String newCP = cptf.getText();
                        boolean b = false;
                        String olcp = jp.setClassPath(newCP,b);
                        updateCPTF();
                   //cpClear
                   else if(source == cpClear){
                        updateCPTF();
                   //qaSubmit
                   else if(source == qaSubmit){
                        JPath jp = new JPath();
                        String newCP = qatf.getText();
                        boolean b = true;
                        String olcp = jp.setClassPath(newCP,b);
                        qatf.setText(null);
                        updateCPTF();
                   //qaClear
                   else if(source == qaClear){
                        qatf.setText(null);
         public class JPath {
              public String getClassPath(){
                   String cp = System.getProperty("java.class.path");
                   return cp;
              public String getPathSep(){
                   String ps = System.getProperty("path.separator");
                   return ps;
              public String getUserName(){
                   String un = System.getProperty("user.name");
                   return un;
              public String getUserHome(){
                   String uh = System.getProperty("user.home");
                   return uh;
              public String getOSName(){
                   String osn = System.getProperty("os.name");
                   return osn;
              public String getOSVersion(){
                   String osv = System.getProperty("os.version");
                   return osv;
              public String setClassPath(String newClassPath, boolean append){
                   String oldClassPath = null;
                   if(append){
                        String cp = getClassPath() + getPathSep() + newClassPath;
                        System.out.println("from setClassPath" + cp);
                        oldClassPath = System.setProperty("java.class.path", cp);
                   else{
                        System.out.println("else - " + newClassPath);
                        oldClassPath = System.setProperty("java.class.path", newClassPath);
                   return oldClassPath;          
         public static void main(String[] args){
              JPathGui jpg = new JPathGui();
    }     

    Two reasons:
    1) Setting the system property java.class.path does not change the value of the CLASSPATH environment variable in the first place.
    2) Even if it did, the change would not be visible in the original shell because the environment of the Java subprocess is destroyed. You can't change the environment of the parent process from any subprocess, including shell scripts. (That's why you have to "source" and not run .bashrc or .profile to customize environment settings)

  • Java Class path for Oracle package compilation

    Hello
    I am trying to send mail with file attachment, this part is
    done by java program, it is compiled & working fine.
    I am trying to compile the same java program at SQL prompt so
    that I can build a package to execute that Java program from
    Oracle. As java prog requires other class files
    (javax.mail.*,javax.mail.internet.*,javax.activation.*) to be
    include , those class path is set at their respective location
    of OS.
    Other Java programs are compiling fine from SQL but for this
    mail prog, it is giving error as it is not finding the location
    of the include files.
    Can anyone tell me from which class path does Oracle 8i compiles
    Java program ? any additional information reqdng this issue ?
    thanks

    Hello Suresh Vemulapalli
    Thanks for replay & suggestion, I compiled using loadjava on
    OS & it is working fine
    regards
    Prakash K.B.

  • How to do java class path on MAC

    Hi
    I have been trying to run a program on MAC, but it complain things like cant find java.io.FileReader and so on.
    So how do I set classpath, so the program finds them.
    please help

    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/mac.html

  • Java class path

    Hi,
    In the environment varaibles I have set the classpath as "C:\j2sdk1.4.2_05\bin". I want to compile java files in the DOS prompt. When typing javac in the classpath, its showing 'javac is not recognized as an internal or external command, operable program or batch file.'
    Is something wrong with the classpath or this is due to some other reasons. Please help.
    Regards
    Ranjith

    This may help:
    http://vlaurie.com/computers2/Articles/environment.htm
    Go to the section on that page named: Adding or Editing Environment Variables for more info.
    Instructions would be:
    Right-click on My Computer and choose "Properties). In the box that opens, click the "Advanced" tab. Next, click the button "Environment Variables".
    Then click on the PATH variable listed under System Variables. Click Edit, and paste ";C:\j2sdk1.4.2_05\bin" at the end of it.
    *Note ';' (semicolon) seperates fields, so to seperate the added path from the end of the old one you need to add ; to the start of your new path. So basically just copy and paste the path as it is typed above in quotes.

  • How can I set Java class path right?

    After I downloaded Java Developer for 10.6 (10M3239a) (Disk Image) 139.4 MB,
    when I opened eclipse it showed 2 errors
    The project cannot be built until path errors are resolved
    Unbound classpath container: 'JRE System Library [Java-1.7]'
    how can i resolve this problem.
    can someone please help me, i am really new to these stuffs.

    I have the exact same problem. I'll try to find out but if someone could help us it would be grate.
    In my error message it says:
    The project cannot be built until path errors are resolved
    Unbound classpath container: 'JRE System Library [JavaSE-1.6]

  • Problem with servicegen and how to convert java classes to webservices

    I am a beginner and am trying to convert all my java code into webservices,I have
    a java class Test.java and number of other third party libraries and my own java
    files that are reffered in Test.java. I want to expose the public methods in Test.java
    as webservices.
    the serivegen part of My build.xml is as below
    <servicegen
    destEar="${APPLICATIONS}/${ear_file}"
    warName="${war_file}">
    <service
    javaClassComponents="com.verizon.Test"
    targetNamespace="${namespace}"
    serviceName="Test"
    serviceURI="/Test"
    generateTypes="True"
    expandMethods="True">
    </service>
    <classpath>
    <pathelement path="${build}"/>
    <pathelement path="${java.class.path}"/>
    </classpath>
    </servicegen>
    When i run ant it complains:
    [servicegen] weblogic.xml.schema.binding.BindingException: Invalid class received:
    interface org.apache.crimson.tree.ElementFactory loaded from file:/apps/opt/crimson.jar!/org/apache/crimson/tree/ElementFactory.class.
    All classes that will be serialized or deserialized must be non-interface, non-abstract
    classes that provide a public default constructor
    I have no clue,Why is Servicegen introspecting the third party class file also?I
    just need the public methods in Test.java exposed and Test.java will just use
    the third party library.
    also,is there a way to tell servicegen to include all these java files X,Y,Z to
    the war file/ear files but expose only the public methods of X in the WSDL.
    Please help
    thanks
    Suresh

    Hi Bruce,
    Thanks very much for the insight u provided.Yes one of my public methods was returning
    a element factory.
    But let me ask my question this way:
    Is there a way to tell servicegen to take only the specified public methods in
    a class to make them as webservices?
    by default servicegen is taking all the public methods..,i workaround i found
    is to deploy the webservice manually by writing the web-services.xml to include
    only the required public methods.
    thanks
    Suresh
    Bruce Stephens <[email protected]> wrote:
    Hi Suresh,
    Does your Test.java have a public method that returns the element
    factory of an XML document, like "public ElementFactory
    getElementFactory ();" or such?
    If so, you may want to check out the supported build-in and non-built-in
    data types:
    http://edocs.bea.com/wls/docs81/webserv/assemble.html#1060696
    Concerning your last question, you can use the excludeEJBs, includeEJBs
    (in combination with the ejbJar attribute) to specify which non-built-in
    data type components should be generated. Or if you use the
    javaClassComponents then simply use a comma separated list of class
    names.
    Hope this helps,
    Bruce
    suresh wrote:
    I am a beginner and am trying to convert all my java code into webservices,Ihave
    a java class Test.java and number of other third party libraries andmy own java
    files that are reffered in Test.java. I want to expose the public methodsin Test.java
    as webservices.
    the serivegen part of My build.xml is as below
    <servicegen
    destEar="${APPLICATIONS}/${ear_file}"
    warName="${war_file}">
    <service
    javaClassComponents="com.verizon.Test"
    targetNamespace="${namespace}"
    serviceName="Test"
    serviceURI="/Test"
    generateTypes="True"
    expandMethods="True">
    </service>
    <classpath>
    <pathelement path="${build}"/>
    <pathelement path="${java.class.path}"/>
    </classpath>
    </servicegen>
    When i run ant it complains:
    [servicegen] weblogic.xml.schema.binding.BindingException: Invalidclass received:
    interface org.apache.crimson.tree.ElementFactory loaded from file:/apps/opt/crimson.jar!/org/apache/crimson/tree/ElementFactory.class.
    All classes that will be serialized or deserialized must be non-interface,non-abstract
    classes that provide a public default constructor
    I have no clue,Why is Servicegen introspecting the third party classfile also?I
    just need the public methods in Test.java exposed and Test.java willjust use
    the third party library.
    also,is there a way to tell servicegen to include all these java filesX,Y,Z to
    the war file/ear files but expose only the public methods of X in theWSDL.
    Please help
    thanks
    Suresh

  • Java 5.0 does not recognize wrapped Class-Path in Manifest.MF of .jar file?

    Java: build 1.5.0_05-b05
    Ant: 1.6.2
    I use Ant <jar> task to create a standalone application in a .jar file. I have a very long "Class-Path" in the Manifest.MF file. The long Class-Path is wrapped at every 70th character by the <jar> task. I cannot run "java -jar <the jar file>", because Java runtime cannot find classes.
    I found the following Q&A from ANT's FAQ page,
    Q: Whenever I use the Ant jar or manifest related tasks, long lines in my manifest are wrapped at 70 characters and the resulting jar does not work in my application server. Why does Ant do this?
    A: Ant implements the Java Jar file specification. Please refer to the notes section where it discusses the maximum allowable length of a line and the concept of continuation characters.
    If a jar file produced by Ant does not work in your appserver, and that failure is due to the wrapped manifest, then you need to consult your appserver provider, as it is a bug in their appserver. Far more likely, however, is a problem in your specification of your classpath. It is not Ant's wrapping of your classpath that is the problem.
    Do not raise a bug about this issue until you have checked to ensure that the problem is not due to your classpath specification.
    Any idea?

    "will be searched ALSO."...
    From: http://java.sun.com/docs/books/tutorial/ext/basics/load.html
    Understanding Extension Class Loading
    The extension framework makes use of the new class-loading mechanism in the JavaTM 1.2 platform. When the runtime environment needs to load a new class for an application, it looks for the class in the following locations, in order:
    1. Bootstrap classes: the runtime classes in rt.jar and internationalization classes in i18n.jar.
    2. Installed extensions: classes in JAR files in the lib/ext directory of the JRE.
    3. The class path: classes, including classes in JAR files, on paths specified by the system property java.class.path. If a JAR file on the class path has a manifest with the Class-Path attribute, JAR files specified by the Class-Path attribute will be searched also.
    [snip]

  • How to find the location of java class files at runtime?

    Does anyonw have an idea how to get the file name of a java class given the binary name?
    I mean how can I get the file name for my class myPackage.myClass?
    I am looking for a function which takes "myPackage.myClass" as input and returns
    "c:\\javaprojects\\myPackage\\myClass.class".
    I tried to do it with the LassLoader class but it did not work. Does anyone have an idea if the Java core API already has a function which does that?
    Thanks, Bernhard

    Hi ,
    It is a simple SAMPLE code , you think and build a logics to handle all classes.
    Try this sample, It doesn't handle the inner classes you put logic to handle the logics for inner classes.
    The inner class format is it contains the character $ in the File location but inside the code you put "." instedad of "$" you to find out or put trials.
    package pkg1;
    import java.io.* ;
    import java.util.* ;
    import java.util.zip.* ;
    public class ClsB {
         private static Vector clsPaths ;
         public static Vector getPaths() {
              if( clsPaths == null ) {
                   String paths = System.getProperty( "java.class.path" ) ;
                   // In linux or solarise use the following
                   // StringTokenizer st = new StringTokenizer( paths , ":\n" ) ;
                   StringTokenizer st = new StringTokenizer( paths , ";\n" ) ;
                   clsPaths = new Vector() ;
                   while( st.hasMoreTokens() ) {
                        String path = st.nextToken() ;
                        File f = new File( path ) ;
                        if( f.exists() ) {
                             try {
                                  f = f.getCanonicalFile() ;
                                  clsPaths.add( f ) ;
                             }catch( IOException ioe ) { }
              return clsPaths ;
         public static String findClassPath( String fullClassName ) {
              Vector v = getPaths() ;
              for( int i = 0 ; i < v.size() ; i++ ) {
                   File f = ( File ) v.get( i ) ;
                   String path = findIn( f , fullClassName ) ;
                   if( path != null )
                        return path ;
              return null ;
         static boolean isJar( File jar ) {
              if( jar.isDirectory() )
                   return false ;
              try {
                   ZipFile zf = new ZipFile( jar ) ;
                   return true ;
              } catch ( ZipException ze ) {
                   // It is not a jar file
                   // you handle this
              } catch ( IOException ioe ) {
                   ioe.printStackTrace() ;
              return false ;
         static String findIn( File dirOrJar , String clsName ) {
              if( isJar( dirOrJar ) ) {
                   // It is something different because the class inside the jar file
                   // Simply I return the jar file location and the entry name ,
                   // but you put action what you want
                   if( isInsideJar( dirOrJar , clsName ) ) {
                        // All archieve file using the path separator is '/'
                        return dirOrJar.getPath() + "!" + clsName.replace( '.' , '/' ) + ".class" ;
              } else {
                   File f = new File( dirOrJar , clsName.replace( '.' , File.separatorChar ) + ".class" ) ;
                   if( f.exists() ) {
                        return f.getPath() ;
              return null ;
         static boolean isInsideJar( File jar , String clsName ) {
              try {
                   ZipFile zf = new ZipFile( jar ) ;
                   // All archieve file using the path separator is '/'
                   ZipEntry ze = zf.getEntry( clsName.replace( '.' , '/' ) + ".class" );
                   return ( ze != null ) ;
              } catch ( ZipException ze ) {
                   ze.printStackTrace() ;
              } catch ( IOException ioe ) {
                   ioe.printStackTrace() ;
              return false ;
         public static void main(String[] args) {
              System.out.println( findClassPath( "pkg1.ClsB" ) );
              System.out.println( findClassPath( "pkg1.pkg2.ClsA" ) );
    }

  • Possible 'Class Path' Issues

    Hi Guys,
    I have problems compiling a file and I suspect it could be something related to classpaths. I am using NetBeans 6.9.1 as my IDE. When I set JDK 1.6 as my platform and complile, there are no issues, the programs compiles fine.
    My 'classpath' and 'path' are as follows:
    classpath:
    .;C:\Program Files\Java\jre1.6.0_07\lib\ext.;c:\java\classes;
    path:
    \....\....\....C:\Program Files\Java\jdk1.6.0_21\
    If I were to set the JDK as in 1.5, I seem to get the follwing error:
    ' cannot access org.red5.server.api.IScope
    bad class file: C:\Program
    Files\Red5\red5.jar(org/red5/server/api/IScope.class)
    class file has wrong version 50.0, should be 49.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    import org.red5.server.api.IScope;
    1 error
    To rectify the problem I maded changes to my classpath and path, and yet the problem persists. The changes I made
    are as follows:
    classpath:
    .;C:\Program Files\Java\jre1.6.0_07\lib\ext.;C:\Program Files\Java\jre1.5.0_22\lib\ext.;c:\java\classes;
    path:
    \....\....\....C:\Program Files\Java\jdk1.6.0_21;C:\Program Files\Java\jdk1.5.0_22;C:\....\
    I hope someone can advise me on how I get rectify the problem and get the program to compile with JDK 1.5. Thanks.

    he wants to use JDK 1.5.Do read the thread before you post. He is* using JDK 1.5 when he gets the error message. He said so. This is the problem.* Not the solution. When he uses 1.6 he doesn't get the error.
    His environment is a bit messed up because he has PATH entries for both JDK versions.There is precisely zero evidence for that assertion.
    If he wants to compile and test with JDK 1.5, then removing 1.6 would make sense.No it wouldn't. He is using classes compiled for 1.6 with a 1.5 compiler. His problem is with red5.jar(org/red5/server/api/IScope.class) whose class version is 50.0. It's all written there above. If he wants to use that .jar file he has to use 1.6. Or else recompile that .jar file with 1.5, if he has the sources.

  • Can not locate Java class using JNI within C++ DLL

    I am using trying to use JNI to call a Java class from C++. The Java class uses JMS to send messages to a JMS message queue. At first I coded the C++ in a console application that created the JavaVM and used JNI to access the Java class. All worked fine. Then I called the Java class using JNI from threads and ran into the problem of the Java class not able to locate the JMS related classes. This was solved by placing the following line in the constructor of the Java class.
    Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
    Then I moved the JNI code from a console application to a DLL in specific an extension DLL that is called by SQL Server or Oracle server. The DLL will use JNI to call the Java class and send messages to a JMS message queue.
    The problem I am having now when the DLL code is called by SQL Server the call to
    JNI_CreateJavaVM
    appears to work correctly but the call to find the Java class using
    jvmEnv->FindClass(pName)
    fails. It appears the is a class loading problem which occurs due to the fact JNI is called from a DLL. When the VM is created I pass the class path information using the statement
    -Djava.class.path=
    And as I stated before it all works when running from a console application. I am new to JNI and really need help in the form of some sample code that will solve this problem. I believe I need to somehow load the classpath information from the DLL but I can not find examples on how to do this using JNI. I have tried several ways using URLClassLoader and getSystemClassLoader from JNI and either it does not work or it crashes very badly.
    I used the following code to determine what the existing class path is and the string returns empty.
    jcls = jvmEnv->FindClass("java/lang/System");
    jmid = jvmEnv->GetStaticMethodID(jcls, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
    jstrClassPath = jvmEnv->NewStringUTF("java.class.path");
    jstr = (jstring)jvmEnv->CallStaticObjectMethod(jcls, jmid, jstrClassPath);
    m_jstr = (jstring)jvmEnv->NewGlobalRef(jstr);
    pstr = jvmEnv->GetStringUTFChars(m_jstr, 0);
    Can anyone please help with example code that will solve this problem. Thanks in advance for any help.
    Charles�

    I have determined the problem occurs when the application/component is compiled using VC 6.0. The test application was compiled using VC 7.1 and works correctly by locating the class path information. If the test application is compiled using VC 6.0 it has the same problem.
    The jvm.dll I am using is version 1.4.2.80. Currently this is not an option to compile all the applications that use JNI using VC 7.1 so can someone please tell me how to solve this problem.

  • Instantiating a Java class in native code.

    I'm trying to figure out how to instantiate a Java class in native code (C/C++) but no luck so far.
    Given a class called DataPacket written in Java, how can I create in the native side of the code?
    Any ideas?
    Thanks.

    chickenlips wrote:
    Hi NiceGuy,
    Thanks for responding. Yes MyClass.class is in the right place.
    A call to env->ExceptionDescribe(); reveals that it can't find org\apache\commons\logging\LogFactory
    Apparently, when I specified:
    options[0].optionString = "-Djava.class.path=c:\My Workspace\JNITest"
    vm_args.options = options;
    It does not append to my classpath environment variable, but instead overwrites it.
    My solution was to list out every jar files I was using and append them to the optionString. Is there a better way to do it?
    A new question: Is there a way to append to the CLASSPATH environment variable using the java.class.path? Or should/could I have use the classpath option instead of the -D option?The 'classpath' option won't be recognized by the Invocation API. To append to the CLASSPATH environment variable, you call call getenv("CLASSPATH") in your native code and use strncat() to concatenate it with your option string.

  • System poerties class path is not working

    I am using reflection to call my class's main method.
    For that i am loading a class by Class.forName method and then calling main method.
    if i am using set classpath="path to be used" command on command prompt then it finds the class, loads it and calls the main method.
    but
    if i am setting the class path by System class
    i.e. System.setProperty("java.class.path", "path to be used") then it is not able to find the class and gives me exception "java.lang.ClassNotFoundException".
    i have also cross checked whether the class path is set properly by calling method System.getProperty("java.class.path"); it returns me the same class path which i had set by calling
    System.setProperty("java.class.path", "path to be used")
    Can you please some one help me to solve this problem where i am missing any step or we can't do this way?
    or you can tell me the alternate way by which i can set the class path dyanamically.

    i want to call the class main method, for that i am sending runtime the class name, and classpath of jar files,
    Problem is with the class path.This work by setting classpath by command promopt's command set classpath. But then every time i have to change the classpath by using set classpath command. i dont want this approch so i am trying to do with System.setProperties("java.class.path","path to be used") but not worked give me exception class not found. please refer the following code.
                                                        System.setProperty("java.class.path", classpath);
                   Class product= Class.forName("className");
                   Class classArray[] = {String.class};
                   Object argsArray[] = {"parameterst to method"};
                   Method mainMethod = product.getMethod("main", classArray);
                   mainMethod.invoke(null, argsArray);With this code it gives me exception class not found.

  • How to set classpath from java class ??

    I have tried to use System.setProperty("java.class.path", "my class path string ") to set classpath dynamically. But it is not working. How to set it dynamically from java class ?? Thanks , gary

    Look into the java.net.URLClassLoader. You can't set the classpath after the fact but you can specify URL's that will checked when you try to load a class with that loader.

  • Jar doesn't populate Class-Path from manifest to target .jar

    I have a manifest file with the following content:
    Manifest-Version: 1.0
    Name: webserver.jar
    Main-Class: Acme.Serve.Serve
    Java-Bean: False
    Class-Path: webserver.jar servlet.jarHowever result META-INF/MANIFEST.MF populated by jar in webserver.jar doesn't have Class-Path entry. What's the trick without manual editing MANIFEST.MF in .jar?

    The following extension of the class Bar.java will at least get the information from the jar file.
    package bar;
    import foo.Foo;
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    import java.util.jar.Attributes;
    import java.util.jar.JarFile;
    import java.util.jar.Manifest;
    public class Bar {
      public static void main(String[] argv) {
        try {
          String classpath = Foo.getPath();
          System.out.println("java.class.path=" + classpath);
          if (!new File(classpath).isDirectory()) {
         JarFile f = new JarFile(classpath);
         Manifest mf = f.getManifest();
         Attributes a = mf.getMainAttributes();
         Iterator keys = a.keySet().iterator();
         while (keys.hasNext()) {
           Attributes.Name key = (Attributes.Name)keys.next();
           String value = a.getValue(key);
           System.out.println(key + "=" + value);
        catch (IOException ioe) {
          System.err.println("Error: " + ioe.getMessage());
    }

Maybe you are looking for

  • Thinkpad W530 backup problem

    I'm experiencing problems when trying to backup my W530, Windows 7-64. This is what happens: If I start the backup session picking up the option "Backup whole disk" it inevitably fails, right at the end, with only two or three minutes left (out of a

  • 5 reports with one query ....?

    Hi Guys, We  are on BI 7 and ECc 6...In one of our MM Report requirements we have one report with 5 work books ...i.e, The report is a set of 5 reports with the same selection criteria with different Key figures. All these reports can be separate wor

  • Flash Active Content Update extension

    I am using flash for advertising, and I usually link to the customers page by this: on (release) { getURL(clickTag, "blank"); and in the script to publish the flash is this: <PARAM NAME=movie VALUE=" http://www.somesite.no/flash.swf?clickTag=http://w

  • OCR VOTE RAW Device mappers

    RHEL4 U5 x64. 2 LUNs. OCR and VOTE, each LUN with 4 paths. I have configured device mapper, assigned the alisas name to the LUNs, and mapped to the raw, modified udev with rules and permissions. In clusterware installation, when it asks root.sh, it f

  • Error reported after Exchange 2013 Setup (initialize-ExchangeUniversalGroups)

    My Exchange 2013 setup reported the error below. Just wondering if someone has experienced this and how easy it was to fix. Error: The following error was generated when "$error.Clear();  initialize-ExchangeUniversalGroups -DomainController $RoleDoma