Frage

Can you see anything wrong with the below code? It's a bat file and I'm trying to set some dependency classes before executing my jar (jdbc oracle driver).

set CLASSPATH=lib\dbdriver.zip;%CLASSPATH%
java -jar sql2java.jar test.properties
pause

I always get class not found exception (the class is in the zip I'm trying to add in the classpath). I even tried this by executing as admin, but to no avail

set CLASSPATH=lib\dbdriver.zip;%CLASSPATH%
java -jar %~dp0sql2java.jar %~dp0test.properties
pause

The class is inside the zip file (path \oracle\jdbc\OracleDriver) and I'm trying to retrieve it with

jdbc.driver=oracle.jdbc.driver.OracleDriver

War es hilfreich?

Lösung

Check this doc about java (Java application launcher).

For the -jar option it says -

Executes a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. For this option to work, the manifest of the JAR file must contain a line in the form Main-Class: classname. Here, classname identifies the class with the public static void main(String[] args) method that serves as your application's starting point.

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

So you either need to package everything in your jar (sql2java.jar) or don't use the -jar option with java launcher command.

Andere Tipps

You can use java -jar to execute it and define a classpath for the application within the jar's manifest file. See the Java Tutorial on jars for how to set a classpath for the application at http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

It says:

For example, in a typical situation an applet is bundled in a JAR file whose manifest references a different JAR file (or several different JAR files) that serves as utilities for the purposes of that applet.

You specify classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the following form:

Class-Path: jar1-name jar2-name directory-name/jar3-name

By using the Class-Path header in the manifest, you can avoid having to specify a long -classpath flag when invoking Java to run the your application.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top