What is classpath?Classpath is used by a Java application to locate the Java classes it needs to run. Classpath lists the directories, .jar files, or .zip files that contain the compiled Java classes. Since these classes could be anywhere on your system or network, you need to specify where to find the classes you are trying to run. The contents of your classpath will vary depending on the system you are running and how your directories are organized. Classpath can be set either as an environment variable, or from the java command line.
Setting classpath correctly is essential for running any Java application. WebLogic Server has some very specific requirements for setting classpath, so care should be taken in setting classpath correctly. For additional information on setting classpath when compiling or running the examples shipped with WebLogic see Setting your development environment.
Packages, directories, .zip files and .jar files
Packages and directories
It can be tricky to figure out exactly what needs to be in your classpath. In order to understand what to put in your classpath, you need to understand a little about Java package names. Package names are well described by JavaSoft in the Java tutorial.
A package name reflects the directory structure of how the Java file
is stored on disk. For example, the class
weblogic.common.T3Client is located inside
/weblogic/classes/weblogic/common/T3Client.class(or in Windows NT)
The directory structure is reflected in the package name. The way we refer to this relationship is as follows: The directory that represents the "left-most" part of the package -- in this example, the "weblogic" of "weblogic.common.T3Client" -- should be contained in the directory (classes, in this case) that you list in your classpath.
That means for this particular package, you'd need to add the directory weblogic/classes to your classpath. If your own classes do not use package names, then you will include the directory or directories that contain your Java class files.
.jar and .zip files
Some products, like the JDK, are shipped with all of the Java classes zipped into a single .zip or .jar file. Other products, like WebLogic Server, are shipped with the classes unzipped. When the classes are in a .zip or .jar file, you need to include the .jar or .zip file itself in the classpath. Otherwise, the classpath just points to a directory.
To start WebLogic Server, use a combination of two classpaths, the Java system classpath and the WebLogic classpath. This enables WebLogic Server to use Dynamic class loading, a process that allows you to deploy, redeploy, and undeploy Enterprise Java Beans and servlets in a running WebLogic Server without restarting WebLogic Server. (Note that you should NOT locate your EJBs in the weblogic.class.path.) For more information on the Hot Deploy feature, see Using WebLogic Server hot deploy.
Note that dynamic classloading works only with JavaSoft JDKs; it does not yet work with the Microsoft SDK for Java (Jview). You can run WebLogic Server without dynamic classloading, but you will need to set your classpath differently.
Java system classpath
The Java system classpath can be set
with the environment variable CLASSPATH or with the
The WebLogic classpath, is set with the weblogic.class.path property on the java command line. The weblogic.class.path property specifies the location of classes that WebLogic Server needs to run.
Setting the Java system classpath in the environmentSetting the Java system classpath in the environment as an environment variable is a common way to set your classpath. However, BEA recommends that you set your classpath on the java command line or in your scripts rather than setting your Java system classpath by setting the CLASSPATH environment variable.
Setting the Java system classpath using the
If you decide to set the Java system classpath in your environment, you must put only those classes detailed in this document as belonging in the Java system classpath in your environment CLASSPATH variable. Instructions for setting the CLASSPATH environment variable vary among platforms and operating systems. Check the documentation for your platform or your JDK for details.
$ java ... -classpath c:/java/lib/classes.zip; c:/weblogic/classes/boot; c:/weblogic/eval/cloudscape/lib/cloudscape.jar ...Note that when you specify a Java system classpath in this manner it will only be in effect when executing the Java class on that command line. You will need to specify it again each time you run the java command.
To start a WebLogic Server
$ java -classpath c:/java/lib/classes.zip; c:/weblogic/classes/boot; c:/weblogic/eval/cloudscape/lib/cloudscape.jar -Dweblogic.class.path=c:/weblogic/classes; c:/weblogic/lib/weblogicaux.jar; c:/weblogic/license; c:/weblogic/myserver/serverclasses weblogic.Server
(Where weblogic is the path to your WebLogic Server installation and java is the path to your JDK.)
To run a JDBC clientAdd the classes for the JDBC driver to the Java system classpath. If you are using one of the supplied WebLogic type 2 JDBC drivers, such as jdbcKona/Oracle, these classes are located in the weblogic/classes directory. For jdbcKona/Informix4, they are located in weblogic/informix4/classes; for jdbcKona/MSSQLServer4, they are located in weblogic/mssqlserver4/classes. For more information, see Setting your development environment.
To run a JDBC driver with a WebLogic multitier driverIf you are using either a WebLogic JDBC driver or a driver from a third party with one of the WebLogic multitier drivers (pool, jts, or t3), append the classes for the driver to the WebLogic classpath when you start WebLogic Server (with the weblogic.class.path property).
The WebLogic classpath is specified using the weblogic.class.path property on the command line when starting WebLogic Server.
For more information, see Using WebLogic JDBC
To run third-party applications with WebLogic ServerAppend the classes for any third-party applications to the WebLogic classpath. The WebLogic classpath is specified using the weblogic.class.path property on the command line when starting WebLogic Server.
To set a classpath for running WebLogic client applications
To run WebLogic java utilities
To compile Java applications with dependencies on WebLogic classesCompiling Java applications requires that you set a Java system classpath to use when running the Java compiler (javac or sj). You must include any classes that are called in your code. If your code calls weblogic.Server, do not forget to include /weblogic/classes/boot in your Java system classpath.
$ javac -classpath c:/java/lib/classes.zip; c:/weblogic/classes/boot; c:/weblogic/classes -d c:/myclasses myJavaCode.java
To start WebLogic Server without dynamic classloadingJview users and other users with special circumstances must use a different Java system classpath to start WebLogic Server that does not use dynamic class loading. Note that a WebLogic Server started in this way will not be able to utilize the hot deploy feature.
To start a WebLogic Server without dynamic classloading:
$ java -ms32m -mx32m -classpath c:/java/lib/classes.zip;c:/weblogic/classes/boot; c:/weblogic/classes; c:/weblogic/license; c:/weblogic/lib/weblogicaux.jar c:/weblogic/myserver/serverclasses weblogic.Server
set JAVA_CLASSPATH=c:/java/lib/classes.zip; c:/weblogic/classes/bootsets the variable JAVA_CLASSPATH for classes belonging in the Java system classpath and
set WL_CLASSPATH=c:/weblogic/license; c:/weblogic/classes;c:/weblogic/lib/weblogicaux.jar;sets the variable WL_CLASSPATH for classes belonging in the WebLogic classpath.
You would then start WebLogic Server with this command:
$ java -ms32m -mx32m -classpath %JAVA_CLASSPATH% -Dweblogic.class.path=%WL_CLASSPATH% weblogic.Server
This information in the Registry is used when you run WebLogic Server from the Windows start menu, as a Windows NT service, or using the Windows convenience program, t3server.exe. This information is not used by any other program.
You may prepend a classpath to Java system classpath used by the
Windows convenience programs with the
$ t3config.exe -classpath c:/myclassesThe InstallShield creates an entry for the weblogic.class.path property in the Registry. You may override this setting with the following command:
$ t3config.exe -Dweblogic.class.path=c:/newPathsNote: If you change the Registry setting for weblogic.class.path, you will completely overwrite the value in the Registry with the new value you specify with t3config. For more information on t3config, including setting other parameters, see Using t3config.
Many problems, especially when you are getting started, can be traced
back to an incorrectly set
The best way to avoid problems is to keep your classpath as simple as
possible. Signs that you may have a classpath problem include:
Other, subtler classpath problems can show up in unexpected
guises. For example, if you get a message like "Unable to initialize
threads" when you try to run a Java program, it probably means that
you have the JDK 1.0.2 classes in your classpath. WebLogic isn't
supported for use with JDK 1.0.2. Your classpath should always point
to the JDK 1.1 or JDK 1.2 classes.
Many problems, especially when you are getting started, can be traced back to an incorrectly set classpath.
The best way to avoid problems is to keep your classpath as simple as possible. Signs that you may have a classpath problem include:
Other, subtler classpath problems can show up in unexpected guises. For example, if you get a message like "Unable to initialize threads" when you try to run a Java program, it probably means that you have the JDK 1.0.2 classes in your classpath. WebLogic isn't supported for use with JDK 1.0.2. Your classpath should always point to the JDK 1.1 or JDK 1.2 classes.
Copyright © 2000 BEA Systems, Inc. All rights reserved.