| Author |
Application not accessing attached JAR file
|
Al Dispennette
Greenhorn
Joined: Jul 16, 2006
Posts: 4
|
|
the following code runs fine in RAD 6.0 but after I export the the .class files into an executable JAR file and try to run it with a batch file it throws a couple errors. the first error is caught when it can't read the external file and the appropriate prompt is displayed(that part is commented out at the moment). the file I'm accessing is locted in a folder in the project and named sysconfig.conf second, to make sure it was the file that was not being read I put a sysout in the code that returned a null. then I hard coded the values into the class to make sure that was all it was, and it was not. I think the executable JAR is not reading the db2j.jar that it needs for recognizing the DB2 driver. Can anyone help with this??? public abstract class JDBC_ConnectionManager { private static String DRIVER = "com.ibm.db2j.jdbc.DB2jDriver"; private static String URL = "jdbc b2j:c:/cloudscapeLightingDatabases/lightingDB"; private static boolean SPECIFY_DATABASE_CREDENTIALS = false; private static String USERID;// = "db2admin"; private static String PASSWORD;// = "db2admin"; private static Connection conn = null; public static Statement stmt = null; public static void readFile() throws IOException { FileReader file = new FileReader("../lighting/config/sysconfig.conf"); BufferedReader buffer = new BufferedReader(file); String record = null; ArrayList array = new ArrayList(); int i = 0; try { while ((record = buffer.readLine()) != null ) { if((record.substring(0,2)).equalsIgnoreCase("//")){ continue; }else{ array.add(record); } i++; } } catch (IOException e) { e.printStackTrace(); } DRIVER = (String)array.get(0); URL = (String)array.get(1); String temp = (String)array.get(2); USERID = (String)array.get(3); PASSWORD = (String)array.get(4); if(temp.equalsIgnoreCase("false")){ SPECIFY_DATABASE_CREDENTIALS = false; }else{ SPECIFY_DATABASE_CREDENTIALS = true; } } public static Connection getConnection() throws SQLException { _/*try { readFile(); } catch (IOException e1) { JOptionPane.showMessageDialog( new JFrame(), "There was an error reading your file", "Error", JOptionPane.PLAIN_MESSAGE); } */ try { System.out.println(DRIVER); Class.forName(DRIVER); } catch (ClassNotFoundException e) { throw new RuntimeException( "Unable to load JDBC Driver: " + e.toString()); } Connection conn = null; if (SPECIFY_DATABASE_CREDENTIALS) { conn = DriverManager.getConnection( URL, USERID, PASSWORD); stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); } else { conn = DriverManager.getConnection(URL); stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); } return conn; } } Manifest file: Manifest-Version: 1.0 Main-Class: ui.Init Class-Path: db2j.jar batch file: @echo off echo Executing files start java -classpath db2j.jar start java.exe -jar lighting.jar manifest.mf Init.class Here is the sysout and the error I get when I run the app using the batch file com.ibm.db2j.jdbc.DB2jDriver Exception in thread "main" java.lang.RuntimeException: Unable to load JDBC Drive r: java.lang.ClassNotFoundException: com.ibm.db2j.jdbc.DB2jDriver at dataAccess.JDBC_ConnectionManager.getConnection(JDBC_ConnectionManage r.java:84)
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
Hi, Welcome to JavaRanch! I'm not sure what you're trying to do here: start java -classpath db2j.jar start java.exe -jar lighting.jar manifest.mf Init.class This runs Java twice. The first time, you're guaranteed to get an error, as it's not a complete command: it would require a class name to be complete. The second line correctly runs "lightning.jar", if it exists, but I'm quite confused as to the additional arguments you've given: the manifest stub file is something that should have been used to create the jar file, and "Init.class" is the name of a class file, something which you'd never specify on the Java command line. So is that manifest actually used to create lightning.jar? Is the db2 driver jar file in the current directory? What are the two lines above intended to do?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Al Dispennette
Greenhorn
Joined: Jul 16, 2006
Posts: 4
|
|
start java -classpath db2j.jar start java.exe -jar lighting.jar manifest.mf Init.class I guess I should combine the two lines into one command, as for the second line I was under the impression that the manifest file had to be specified in the command line as well. all of the jar files ar in the same folderalong with the config file.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
Note that when you use the -jar switch, the -classpath switch is ignored. The manifest file belongs on the command line of the "jar" command when you create a jar file, not on the java command line.
|
 |
Al Dispennette
Greenhorn
Joined: Jul 16, 2006
Posts: 4
|
|
Note that when you use the -jar switch, the -classpath switch is ignored. The manifest file belongs on the command line of the "jar" command when you create a jar file, not on the java command line. <u>new batch file:</u> @echo off echo Lighting system execution start java -classpath db2j.jar -jar lighting.jar <u>your saying it should be:</u> @echo off echo Lighting system execution start java -jar lighting.jar this still fails to read the db2j.jar that is located in the same directory as the lighting.jar when the application runs the DRIVER field is populated correctly yet the application stops at the catch statement after Calss.forName(DRIVER) this is why I believe the db2j.jar is not being read and why I added the -classpath to the command line argument. either way I run the batch file the application fails to open correctly. I hope I am explaining this clear enough if not sorry for that.
|
 |
 |
|
|
subject: Application not accessing attached JAR file
|
|
|