Adding a JAR to Your ClasspathAlthough Appendix A, "Installing the SDK and Getting Started," describes installation of the SDK and touches on ensuring that the JAR files are in your System CLASSPATH, you should understand how to add other JAR files to your CLASSPATH. These other JAR files could be your own JAR files for you application or a third-party vendor's JAR files. The good news is that it's no different than adding the JAR files for the SDK. You can specify them by appending them to your system CLASSPATH after the JAR files from the SDK. When adding JAR files, however, keep in mind that if you have a class that exists in two different JAR files, or even one JAR file and then a directory that contains Java class files, the first class of that name a Java application reads will be loaded. Of course, if you use packages, the problem is not so likely to occur. Packages can help resolve this problem if two different developers use the same name for a class, but put the classes into a different package name . You can also append JAR files on the command line when running your applications. You can do this by using the "cp option when executing the java command. Here's an example that works on Windows: java "cp %CLASSPATH%;test1.jar;test2.jar SomeApplication This command tells the virtual machine to append the test1.jar and test2.jar files to the system classpath and then run the application using the SomeApplication class. Of course, the format of the search path is different for different platforms. On Unix, instead of a semicolon, you must use a colon . |