Java Reference
In-Depth Information
Using Extensions or Other Packaged APIs
Problem
You have a JAR file of classes you want to use.
Solution
Simply add the JAR to your CLASSPATH.
Discussion
As you build more sophisticated applications, you will need to use more and more third-
party libraries. You can add these to your CLASSPATH.
It used to be recommended that you could drop these JAR files into the Java Extensions
Mechanism directory, typically something like \jdk1.x\jre\lib\ext ., instead of listing each JAR
file in your CLASSPATH variable. However, this is no longer generally recommended.
The benefit of using CLASSPATH rather than the extensions directory is that it is more clear
what your application depends on. Programs like Ant (see Automating Compilation with
Apache Ant ) or Maven (see Automating Dependencies, Compilation, Testing, and Deploy-
ment with Apache Maven ) as well as IDEs can simplify or even automate the addition of
JAR files to your classpath.
A further drawback to the use of the extensions directory is that it requires modifying the in-
stalled JDK or JRE, which can lead to maintenance issues, or problems when a new JDK or
JRE is used.
It is anticipated that Java 9 will provide a new mechanism for program modularization, so
you may not want to invest too heavily in anything complicated here. Use the existing tools
mentioned earlier.
Parsing Command-Line Arguments
Problem
You need to parse command-line options. Java doesn't provide an API for it.
Search WWH ::




Custom Search