Driver in Jar classpath

my application is in App.jar
when running from command line >java -jar App.jar it is not finding the JDBC:MYSQL driver even though in the JAR manifest there is
Class-Path: .......\mysql-connector-java-3.2.0-alpha-bin.jar
as an absolute path from root.
Any ideas why not?
thanks

sounds like the Class-Path is set properly in the manifest, but the JAR isn't in the right place.
I wouldn't recommend making the path absolute from root. I'd make it relative to the location of the executable JAR.
I'll also assume that you know that you have to deploy all the 3rd party JARs along with the executable JAR, and that the 3rd party JARs are outside the executable JAR.
%

Similar Messages

  • How can i load  microsoft SQL Server driver in the classpath ?

    Hi
    i need to have microsoft SQL Server driver in the classpath , how can i do that to run the following code :
    String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    Class.forName(driver);
    with best regards

    Just as information, if you need to load a JDBC driver dynamically without previously knowing its name (meaning you can't add it to the classpath manually in your startup batch), the following will not work:
    // register the SQL driver as necessary
    DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
    // connect to the DB by using the driver.
    String connString = "my_dbserver:1433;databasename=my_database";
    String strDBConnect = "jdbc:microsoft:sqlserver://" + connString;
    conn = DriverManager.getConnection(strDBConnect, userName, passwd);
    This is because the DriverManager.getConnection checks if the loaded class was loaded by the same class loader than itself. And for dynamic scenarios, you need a new classloader for the new classes.
    Above, the class will be loaded correctly, but getConnection will fail.
    This behaviour costed me several hours while developing a dialog for adding drivers dynamically, until I saw the reason.
    But a solution has been posted in the forums, which goes like this:
    // jdbcLoader is my individual class loader, you can construct it with the driver url
    Class driverClass = Class.forName(driverName, true, jdbcLoader);
    currDriver = (Driver)driverClass.newInstance();
    // problem: classes which were loaded in custom class loader are not recognized by DriverManager. So the following would fail:
    // conn = DriverManager.getConnection(...)
    Properties prop = new Properties();
    prop.setProperty("user", (String)paras.get("youruser");
    prop.setProperty("password", (String)paras.get("yourpwd");
    conn = currDriver.connect((String)paras.get("yourURL", prop); // this one works for all classloaders
    But in your case, it seems to be enough to add the file manually, as was described in previous replies...
    Regards,
    Christian Sy

  • Oracle Type4 driver (ojdbc14.jar) connection proble

    Hi,
    I'm trying to connect to my oracle 8i installed in my local machine through type4 driver.
    I've downloaded ojdbc14.jar and included its path to classpath
    The following lines are included in my code
    Class.forName("oracle.jdbc.OracleDriver");
    cn = DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@localhost:1521:dbmsConnect ")
    I've created the DSN as follows (in Windows XP)
    Control Panel - Administrative Tools - Data Sources - Add - Took Oracle ODBC Driver - entered DSN name as dbmsConnect -added user id as scott
    When I ran the code, Igot following exception
    Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=135286784)(ERR=12505)
    (ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
    Could anyone help me please

    You may need a later version of the driver:
    http://www.dbforums.com/showthread.php?t=971271
    Pl. also see:
    http://forum.java.sun.com/thread.jspa?threadID=563288&messageID=2773243
    http://forum.java.sun.com/thread.jspa?threadID=300137&messageID=1189780

  • Installing a JDBC-driver in the classpath in win 2000

    Hi
    I'm trying to make an aplication, that can access a remote DataBase, with the mm.mysql driver.
    I have tryed to add the path to the libery where the jar file is in the classpath (in win 2000). But I can't get it to work from a dos-promt.

    put it in your enviroment.
    Control Panel -> System -> Enviroment.

  • Loading JDBC driver dynamicly (without CLASSPATH)

    Problem:
    Need loading driver for database MySQL without
    using enviroment variable CLASSPATH.
    I try this using URLClassLoader
    URL []url = new URL[1];
    url[0] = new URL("file:\\d:\\Sergei\\Work\\MySlateDB\\MySqlDriver\\mm.mysql-2.0.6.jar");
    URLClassLoader loader = new URLClassLoader(url);
    DriverManager.registerDriver((Driver)Class.forName("org.gjt.mm.mysql.Driver",true,loader).newInstance());//.newInstance();
    Enumeration e=DriverManager.getDrivers();
    Driver loading, but DriverManager do not register it.
    Enumeration e is empty....
    Connection cn = DriverManager.getConnection("jdbc:mysql:\\172.16.9.200\\astra?user=SERGEY&password=QWE");
    And accordingly create exception "no Suitable driver"
    Why DriverManager do not register driver ?
    if add jar-archive in CLASSPATH then all working.
    How solve this problem ?
    Best regards, Rinver.

    You going to have to write your own version of DriverManager to do this. java.sql.DriverManager only uses the system classloader to load JDBC drivers.
    You can get an example from here:
    http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/squirrel-sql/squirrel-sql/fw/src/net/sourceforge/squirrel_sql/fw/sql/
    The files you are interested in are SQLDriverManager.java and SQLDriverClassLoader.java.
    Col

  • How to add JDBC Driver to my CLASSPATH

    Hi~
    I use MySQL JDBC Driver in my program like that
    Class.forName("com.mysql.jdbc.Driver");But when I try to run it, I got a ClassNoFound Exception,I hava add mysql-connector-java-5.0.3-bin.jar into my CLASSPATH, but it no use.How to fix it ?
    Thanks for your time~ ^_^

    Here's my code, Thank you very much. But I suggest that,you'd better write your own code to test it. Hehe,thanks~~
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    public class DBTest {
         private static Connection getConnection(String url, String username, String password)
              throws SQLException, IOException{
                   try{
                        Class.forName("com.mysql.jdbc.Driver");
                   }catch(ClassNotFoundException e){
                        e.printStackTrace();
              return DriverManager.getConnection(url, username, password);
         private static void runTest(){
              Scanner stdin = new Scanner(System.in);
              String serverUrl, username, password;
              serverUrl = "jdbc:mysql://localhost:3306/test";;
              username = stdin.nextLine();
              password = stdin.nextLine();
              Connection conn =null;
              try{
                   conn = getConnection(serverUrl, username, password);
              }catch(SQLException e){
                   e.printStackTrace();
              }catch(IOException e){
                   e.printStackTrace();
              }finally{
              try{
                   Statement stat;
                   if(conn != null){
                         stat = conn.createStatement();
                         stat.executeUpdate("CREATE TABLE Greetings (Message VARCHAR(20))");
                         stat.executeUpdate("INSERT INTO Greetings VALUES('Hello mysql')");
                         ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
                         result.next();
                         System.out.println(result.getString(1));
                   //      stat.executeUpdate("DROP TABLE Greetings");
              }catch(SQLException e){
                   e.printStackTrace();
              }finally{
                   try{
                        if(conn != null)
                             conn.close();
                   }catch(SQLException e){
                        e.printStackTrace();
         public static void main(String args[]){
              runTest();          
    }

  • Can't found Driver class, but CLASSPATH is set!!!

    I know this must be a favorite, but I have searched for 2 hours and can't found a solution for my problem. when I call Class.forName("com.mysql.jdbc.Driver").newInstance(); it throws the following exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
    I have set the CLASSPATH and in Netbeans I have the Driver in fact I can connect to the Database in the Services tag, but I can't connect to it when I run the application.
    I have connector/j version 5.1.6
    Java Version 1.6.0_03
    LinuxMint.
    Please help.

    odrium wrote:
    I know this must be a favorite, but I have searched for 2 hours and can't found a solution for my problem. when I call                Class.forName("com.mysql.jdbc.Driver").newInstance(); it throws the following exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
    I have set the CLASSPATH Believe the class loader - it can't find it. That means you did it incorrectly.
    If CLASSPATH is an environment variable for you, I can assure you that it's incorrect. All IDEs and app servers ignore any CLASSPATH environment variables. It's worthless. I don't have one on any machine I work on.
    and in Netbeans I have the Driver in fact I can connect to the Database in the Services tag, but I can't connect to it when I run the application.Best to add those JARs to the CLASSPATH the way NetBeans uses it. It's got to have a way to add 3rd party JAR dependencies.
    %

  • Alternate drives in Jar file Class-Path attribute

    Hello, all. I am working on a project that I would like to package into a single jar file for simple execution. At my place of work classes from EJB are stored on a different drive from where I am doing the development. I am having trouble accessing those classes from the Jars I am creating. When I try the following manifest:
    Main-Class: MyPackage.MyClass
    Class-Path: U:\someFolder
    the application will not start, saying that MyPackage.MyClass cannot be found. This is despite MyPackage.MyClass being properly packaged into the Jar file, as verified by a jar t operation. When I leave off the drive letter in the Class-Path attribute:
    Main-Class: MyPackage.MyClass
    Class-Path: someFolder
    the application starts and executes properly right up until a class from someFolder is needed, at which point exceptions begin to be thrown.
    Any ideas will be much appreciated!
    John Todd

    I was eventually able to find the answer to my own question: Jars do not accept absolute paths at all, only relative paths. Thus, the alternate drive approach will not work. Fortunately I was able to find an alternate solution.
    John Todd

  • Include driver in jar file

    Hi, i need include de jdbc driver for postgres en my jar application file...
    i use netbeans 4 but i dont know make this...
    Help meeeeeeeeeeeeeee

    It's not just the driver, of course, the driver will connect to every other class in the postgres jar file. You can extract all the files from the jar, creating a directory tree and then combine that tree with your own class tree before building a new jar. If you expand into build/classes then I think the jar target will include them.
    "jar xf xxxx.jar" will do the unpacking.
    You should also probably take a look at the GenJar project on sourceforge if you're going to do this sort of thing. It's a tool which works out what classes are needed from many sources and assembles them into a jar.

  • Problem registering jdbc driver in jar

    My java oracle program runs fine as a class.
    (java myclass)
    But when I run the program as an executable jar (java -jar myclass.jar), a statement like
    Class.forName("oracle.jdbc.driver.
    OracleDriver"); throws the ClassDefNotFound exception, in other words it can not find and load the driver class !
    Any solutions ?
    Thanks

    I had the same issue, as a work around I included classes12.zip (in my case) in a sub directory from my application /jdbc. Then added the following line to the manifest
    Class-Path: jdbc/classes12.zip
    Hope this helps

  • Multiple jars - CLASSPATH - etc. kind of solution.

    Hi all,
    after long trials I found that before executing packager.exe, if you place the jar files that will be referenced from the JavaBeans class into $Private_JRE\lib\ext (probably C:\j2sdk1.4.2\jre\lib\ext), it can load referenced classes and generates .dll successfully.
    of course you have to copy those jars into $Public_JRE\lib\ext (probably C:\Program Files\Java\j2re1.4.2\lib\ext) so classes can be loaded at run time.
    anyways, at the end, it seems to be working fine.
    ps: I'm so disappointed with Sun's support on this forum & documentation on this new bridge stuff.
    regards.
    Erdem.

    A few things:
    If you have a class that is a part of a package, most likely, you'd like to JAR it with the same exposed (to COM) class, but it depends on your deployment needs
    If you want a class to be able to access other class you have the following 3 options:
    1. JAR it together. (some time it makes sense)
    2. Put the additional class in a jar in the <jre>/lib/ext
    3. Change the classpath to ALL of the machine, this is <strong>NOT</strong> done via changing the classpath, but rather by changing the classpath in the Java Control Panel
    Where <jre> can be pretty much anything, look at the ControlPanel and see your options there.
    Yossi

  • Deployment using AIA Install Driver - Composite jar creation

    Hi All,
    I am trying to deploy all my composite using AIA Install driver.
    But i want my script to divided between build and deploy.
    Hence i would like to know at what step are the composite jar files created?
    Appreciate your help on this.
    Thanks & Regards,
    Amit

    Amit,
    in general, the AIA Install Driver does not support this split up into build and deployment. It is certainly technically feasible by tweaking the underlying ant / wlst scripts, but I also don't see why this would be useful. The 'deployment' action of AID consists of even more than build and deploy, namely adjusting the composite to match an environment, i.e. adjust references, URLs, etc. to match the current environment, e.g. when you take your code from dev to test.
    So rather than giving jars (containing "wrong" references) to somebody being in charge to deploy it somewhere else, our recommendation is to package up the code of the composites with the deployment plan. With that package, somebody else can just lay this down on any other server and execute the bundled deployment plan. As said above, that will take care of adjusting this code to this particular environment. On the other hand, if you would pass jars, you would have to know in advance(!) the target environment to be able to adjust accordingly and compile it into the jar. This is not practical and AID just offers a much more convenient way.
    Gerhard

  • Starting app with -jar : classpath  doesnt work

    I have a jar file called netcdfAll.jar with this manifest:
    Manifest-Version: 1.0
    Created-By: Apache Ant 1.5.1
    Main-Class: ucar.nc2.ui.ToolsUI
    Class-Path: prefsAll.jar units.jar HTTPClient.jar jdom.jar
    Built-By: john
    Built-On: 2003-12-04 18:36:43
    but i get this error
    + java -Xmx512m -jar netcdfAll.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: ucar/util/prefs/XMLStore
    at ucar.nc2.ui.ToolsUI.main(ToolsUI.java:761)
    but with no other changes this works:
    + java -Xmx512m -classpath netcdfAll.jar;prefsAll.jar;units.jar;HTTPClient.jar;jdom.jar ucar.nc2.ui.ToolsUI
    sorry to be so stupid, but i cant seem to see whats wrong here. the manifest is not wrapping to the next line. can anyone help?
    BTW, heres an octal dump:
    $ od -bc MANIFEST.MF
    0000000 115 141 156 151 146 145 163 164 055 126 145 162 163 151 157 156
    M a n i f e s t - V e r s i o n
    0000020 072 040 061 056 060 015 012 103 162 145 141 164 145 144 055 102
    : 1 . 0 \r \n C r e a t e d - B
    0000040 171 072 040 101 160 141 143 150 145 040 101 156 164 040 061 056
    y : A p a c h e A n t 1 .
    0000060 065 056 061 015 012 115 141 151 156 055 103 154 141 163 163 072
    5 . 1 \r \n M a i n - C l a s s :
    0000100 040 165 143 141 162 056 156 143 062 056 165 151 056 124 157 157
    u c a r . n c 2 . u i . T o o
    0000120 154 163 125 111 015 012 103 154 141 163 163 055 120 141 164 150
    l s U I \r \n C l a s s - P a t h
    0000140 072 040 160 162 145 146 163 101 154 154 056 152 141 162 040 165
    : p r e f s A l l . j a r u
    0000160 156 151 164 163 056 152 141 162 040 110 124 124 120 103 154 151
    n i t s . j a r H T T P C l i
    0000200 145 156 164 056 152 141 162 040 152 144 157 155 056 152 141 162
    e n t . j a r j d o m . j a r
    0000220 015 012 102 165 151 154 164 055 102 171 072 040 152 157 150 156
    \r \n B u i l t - B y : j o h n
    0000240 015 012 102 165 151 154 164 055 117 156 072 040 062 060 060 063
    \r \n B u i l t - O n : 2 0 0 3
    0000260 055 061 062 055 060 064 040 061 070 072 063 066 072 064 063 015
    - 1 2 - 0 4 1 8 : 3 6 : 4 3 \r
    0000300 012 015 012
    \n \r \n
    0000303

    it appears to be a bug in ant, i have submitted an error report to them.
    http://issues.apache.org/bugzilla/show_bug.cgi?id=25255
    i will say that whatever is failing is not obvious, that the "good" and "bad" manifest files seem identical except for the ordering.
    $ cat manifest.bad
    Manifest-Version: 1.0
    Created-By: Apache Ant 1.5.1
    Main-Class: ucar.nc2.ui.ToolsUI
    Class-Path: prefsAll.jar HTTPClient.jar units.jar jdom.jar
    $ cat manifest.good
    Manifest-Version: 1.0
    Class-Path: prefsAll.jar HTTPClient.jar units.jar jdom.jar
    Created-By: Apache Ant 1.5.1
    Main-Class: ucar.nc2.ui.ToolsUI

  • Any easy way to set *.jars classpath in windows

    Is any easy way to set the classpath for serveral jars in windows?
    for example, if I have 1000 jars in a folder "C:/MyJar", is this the only way to set the classpath with:
    CLASSPATH=C:/MyJar/Jar0001.jar; C:/MyJar/Jar0002.jar; C:/MyJar/Jar0003.jar; .........; C:/MyJar/Jar1000.jar
    ?

    Is any easy way to set the classpath for serveral jars
    in windows?
    for example, if I have 1000 jars in a folder
    "C:/MyJar", is this the only way to set the classpath
    with:
    CLASSPATH=C:/MyJar/Jar0001.jar; C:/MyJar/Jar0002.jar;
    C:/MyJar/Jar0003.jar; .........; C:/MyJar/Jar1000.jar
    ?You shouldn't have a system CLASSPATH environment variable.
    You don't add every JAR for every project to a system CLASSPATH. You should be doing it on a project-by-project basis, preferrably with a script or an Ant build.xml.
    Doing it with a system environment variable makes your apps less portable, because now you depend on the target machine being set up in a particular way. You should figure out how to package your apps appropriately so clients don't have to worry about that setup issue.

  • Sunone8.2 jar classpath(jar) problem plz suggest

    I have sunone8.2 ,while placing the external jar files under any “domain_dir/lib/ext “folder was creating an issue while server startup.Server will simply shut down and i am not able to start server again.
    Please suggest what can be the problem

    I have sunone8.2 ,while placing the external jar files under any “domain_dir/lib/ext “folder was creating an issue while server startup.Server will simply shut down and i am not able to start server again.
    Please suggest what can be the problem

Maybe you are looking for