Corporate Info | News | Solutions | Products | Partners | Services | Events | Download | How To Buy

# Setting classpath Contents What is classpath? Packages, directories, zip files and jar files Setting classpath for WebLogic Server Important note regarding WebLogic RMI over IIOP Java system classpath WebLogic classpath Setting the Java system classpath Setting the Java system classpath in the environment Setting the Java system classpath from the Java command line What to put in your classpath to start a WebLogic Server Important note regarding WebLogic RMI over IIOP To run a JDBC client To run a JDBC driver with a WebLogic multitier driver To run third-party applications with WebLogic Server to run client applications to run WebLogic Java utilities to compile Java applications using WebLogic classes to run WebLogic Server without dynamic classloading Using variables to set classpath Common problems and solutions # 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 (in UNIX)
      /weblogic/classes/weblogic/common/T3Client.class
(or in Windows NT)
      c:\weblogic\classes\weblogic\common\T3Client.class
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. # Setting classpath for WebLogic Server 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. ### Important note regarding WebLogic RMI over IIOP If you are using WebLogic RMI over IIOP, you must set your classpath differently than is described in this document. For details, see Using WebLogic RMI over IIOP. ### Java system classpath The Java system classpath can be set with the environment variable CLASSPATH or with the -classpath option from the java command line. The Java system classpath contains classes needed to start WebLogic Server. ### WebLogic classpath 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 ### Setting the Java system classpath in the environment Setting 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 -classpath option on the Java command line setting overrides any environment settings and therefore prevents extraneous classes from being loaded. Setting classpath in this manner also allows you to set different Java system classpaths for different applications, which is often necessary when developing and deploying applications using WebLogic Server. For convenience, you may wish to set up your own variables to substitute for commonly used classpaths. 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. ### Setting the Java system classpath from the java command line You can set your Java system classpath from the java command line with the -classpath option. This setting will override any classpath previously set in the environment. For example:
      $ 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. # What to include in your classpath Depending on the Java application you are running, the classes you include in your classpath will vary. This section tells you how to set your classpath to start a WebLogic Server and to perform other common tasks. Since each task requires a different classpath -- one that can be laborious to type -- you may wish to set up variables to represent these various classpaths. See Using variables to set classpath for details. ### To start a WebLogic Server Specify the following classes in the Java system classpath: classes.zip file located in the java/lib directory of your Java installation. Omit this entry if you are running under Java 2 (JDK 1.2.x). weblogic/classes/boot weblogic/eval/cloudscape/lib/cloudscape.jar You may omit this if you will NOT be using the evaluation copy of the Cloudscape DBMS included with the WebLogic distribution. Specify the following classes in the WebLogic classpath, using the weblogic.class.path property. weblogic/classes weblogic/lib/weblogicaux.jar weblogic/license weblogic/myserver/serverclasses For example:
    $ 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.) #### Important note regarding WebLogic RMI over IIOP If you are using WebLogic RMI over IIOP, you must set your classpath differently than is described in this document. For details, see Using WebLogic RMI over IIOP. ### To run a JDBC client Add the classes for the JDBC driver to the Java system classpath. If you are using WebLogic jDriver for Oracle, the Type 2 JDBC driver supplied with WebLogic, the classes are located in the weblogic/classes directory. For WebLogic jDriver for Informix, the classes are located in weblogic/informix4/classes; for WebLogic jDriver for Microsoft SQL Server, the classes are located in weblogic/mssqlserver4/classes. For more information, see Setting your development environment. ### To run a JDBC driver with a WebLogic multitier driver If 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). WebLogic Type 2 JDBC drivers If you are using WebLogic jDriver for Oracle, the Type 2 JDBC driver supplied with WebLogic, the classes are located in the weblogic/classes directory and are always included in the classpath used to run WebLogic Server. WebLogic jDriver for Informix Append weblogic/informix4/classes to your WebLogic classpath (with the weblogic.class.path property). WebLogic jDriver for Microsoft SQL Server Append weblogic/mssqlserver4/classes to your WebLogic classpath (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 Server Append 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 the classes.zip file located in the java/lib directory of your Java installation. Omit this entry if you are running under Java 2 (JDK 1.2.x). weblogic/classes weblogic/lib/weblogicaux.jar weblogic/license weblogic/myserver/clientclasses paths for user-written or third-party Java classes (Where weblogic is the path to your WebLogic Server installation.) ### To run WebLogic java utilities classes.zip file located in the java/lib directory of your Java installation. Omit this entry if you are running under Java 2 (JDK 1.2.x). weblogic/classes weblogic/lib/weblogicaux.jar (Where weblogic is the path to your WebLogic Server installation.) For example, to run a utility called utils.dbping:
      $ java -classpath c:/java/lib/classes.zip;
          c:/weblogic/classes;
          c:/weblogic/lib/weblogicaux.jar utils.dbping
### To compile Java applications with dependencies on WebLogic classes Compiling 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. For example,
     $ 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 classloading Jview 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: Include the following classes in the Java system classpath, with the -classpath (JavaSoft JDK) or /cp (Jview) option on the command line: the classes.zip file located in the java/lib directory of your Java installation. Omit this entry if you are running under Java 2 (JDK 1.2.x). weblogic/classes/boot weblogic/eval/cloudscape/lib/cloudscape.jar (If you will be using the Cloudscape DBMS.) weblogic/classes weblogic/lib/weblogicaux.jar weblogic/license weblogic/myserver/serverclasses Do not set the WebLogic classpath using the weblogic.class.path property on the java command line. The WebLogic classpath is only used when starting WebLogic Server with dynamic class loading. For example:
    $ 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
# Using variables to set classpath You may set up your own environment variables to help you set classpath for various uses. For instance, you may wish to set up variables for the WebLogic classpath and the Java system classpath to be used when: running WebLogic Server running Java utilities running client code running your own applications compiling Java code Consult the documentation for your operating system for information on how to define environment variables. For example:
      set JAVA_CLASSPATH=c:/java/lib/classes.zip;
        c:/weblogic/classes/boot
sets 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
# Windows convenience programs When you install WebLogic Server with the InstallShield on Windows NT, the InstallShield automatically creates Windows Registry entries which store information about classpath and the location of your WebLogic installation. 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, wlserver.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 wlconfig.exe -classpath command. You must run wlconfig.exe from the weblogic/bin directory, or add that directory to your system PATH. For example:
     $ wlconfig.exe -classpath c:/myclasses
The InstallShield creates an entry for the weblogic.class.path property in the Registry. You may override this setting with the following command:
     $ wlconfig.exe -Dweblogic.class.path=c:/newPaths
Note: 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 wlconfig. For more information on wlconfig, including setting other parameters, see Using wlconfig. # Common problems and solutions 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: Java says "Can't find class ..." when you try to run a program. You get one of these messages when you compile your code: Package weblogic.common not found in import or Class weblogic.common.T3Client not found in type declaration You get a java.lang.NoClassDefFoundError when you run a Java program. You get a java.lang.ClassNotFoundException when you run a Java program. (The typical cause of this exception, as opposed to the NoClassDefFoundError, is that the code does a Class.forName() on a class that can't be found.) 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. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher. Last updated 09/02/1999