This article has multiple issues. Please help improve it or discuss these issues on the talk page . (Learn how and when to remove these template messages)
|
Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable.
Similar to the classic dynamic loading behavior, when executing Java programs, the Java Virtual Machine finds and loads classes lazily (it loads the bytecode of a class only when the class is first used). The classpath tells Java where to look in the filesystem for files defining these classes.
The virtual machine searches for and loads classes in this order:
jre/lib/ext/
By default only the packages of the JDK standard API and extension packages are accessible without needing to set where to find them. The path for all user-defined packages and libraries must be set in the command-line (or in the Manifest associated with the Jar file containing the classes).
Suppose we have a package called org.mypackage containing the classes:
and the files defining this package are stored physically under the directory D:\myprogram (on Windows) or /home/user/myprogram (on Linux).
The file structure looks like this:
Microsoft Windows | Linux |
---|---|
D:\myprogram\ | ---> org\ | ---> mypackage\ | ---> HelloWorld.class ---> SupportClass.class ---> UtilClass.class | /home/user/myprogram/ | ---> org/ | ---> mypackage/ | ---> HelloWorld.class ---> SupportClass.class ---> UtilClass.class |
When we invoke Java, we specify the name of the application to run: org.mypackage.HelloWorld. However we must also tell Java where to look for the files and directories defining our package. So to launch the program, we use the following command:
Microsoft Windows | Linux |
---|---|
java -classpath D:\myprogram org.mypackage.HelloWorld | java -cp /home/user/myprogram org.mypackage.HelloWorld |
where:
java
is the Java runtime launcher, a type of SDK Tool (A command-line tool, such as javac, javadoc, or apt)The environment variable named CLASSPATH
may be alternatively used to set the classpath. For the above example, we could also use on Windows:
D:\myprogram>setCLASSPATH=D:\myprogram D:\myprogram>java org.mypackage.HelloWorld
The rule is that -classpath
option, when used to start the java application, overrides the CLASSPATH
environment variable. If none are specified, the current working directory is used as classpath. This means that when our working directory is D:\myprogram\
(on Linux, /home/user/myprogram/
), we would not need to specify the classpath explicitly. When overriding however, it is advised to include the current folder "."
into the classpath in the case when loading classes from current folder is desired.
The same applies not only to java launcher but also to javac, the java compiler.
If a program uses a supporting library enclosed in a Jar file called supportLib.jar, physically located in the directory D:\myprogram\lib\ and the corresponding physical file structure is:
D:\myprogram\ | ---> lib\ | ---> supportLib.jar | ---> org\ | --> mypackage\ | ---> HelloWorld.class ---> SupportClass.class ---> UtilClass.class
the following command-line option is needed:
java -classpath D:\myprogram;D:\myprogram\lib\supportLib.jar org.mypackage.HelloWorld
or alternatively:
D:\myprogram>setCLASSPATH=D:\myprogram;D:\myprogram\lib\supportLib.jar D:\myprogram>java org.mypackage.HelloWorld
In Java 6 and higher, one can add all jar-files in a specific directory to the classpath using wildcard notation.
Windows example:
D:\myprogram>java -classpath ".;c:\mylib\*" MyApp
Linux example:
$ java-classpath'.:/mylib/*'MyApp
This works for both -classpath
options and environment classpaths.
If a program has been enclosed in a Jar file called helloWorld.jar, located directly in the directory D:\myprogram, the directory structure is as follows:
D:\myprogram\ | ---> helloWorld.jar | ---> lib\ | ---> supportLib.jar
The manifest file defined in helloWorld.jar has this definition:
Main-Class:org.mypackage.HelloWorldClass-Path:lib/supportLib.jar
The manifest file should end with either a new line or carriage return.
The program is launched with the following command:
java -jar D:\myprogram\helloWorld.jar [app arguments]
This automatically starts org.mypackage.HelloWorld specified in class Main-Class with the arguments. The user cannot replace this class name using the invocation java -jar
. Class-Path describes the location of supportLib.jar relative to the location of the library helloWorld.jar. Neither absolute file path, which is permitted in -classpath
parameter on the command line, nor jar-internal paths are supported. This means that if the main class file is contained in a jar, org/mypackage/HelloWorld.class must be a valid path on the root within the jar.
Multiple classpath entries are separated with spaces:
Class-Path:lib/supportLib.jar lib/supportLib2.jar
Being closely associated with the file system, the command-line Classpath syntax depends on the operating system. [1] For example:
This does not apply when the Classpath is defined in manifest files, where each file path must be separated by a space (" "), regardless of the operating system.
A JAR file is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution.
GNU Classpath is a free software implementation of the standard class library for the Java programming language. Most classes from J2SE 1.4 and 5.0 are implemented. Classpath can thus be used to run Java-based applications. GNU Classpath is a part of the GNU Project. It was originally developed in parallel with libgcj due to license incompatibilities, but later the two projects merged.
Apache Ant is a software tool for automating software build processes for Java applications which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implemented using the Java language and requires the Java platform. Unlike Make, which uses the Makefile format, Ant uses XML to describe the code build process and its dependencies.
The cron
command-line utility is a job scheduler on Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs, also known as cron jobs, to run periodically at fixed times, dates, or intervals. It typically automates system maintenance or administration—though its general-purpose nature makes it useful for things like downloading files from the Internet and downloading email at regular intervals.
In computer programming, glob patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txttextfiles/
moves all files with names ending in .txt
from the current directory to the directory textfiles
. Here, *
is a wildcard and *.txt
is a glob pattern. The wildcard *
stands for "any string of any length including empty, but excluding the path separator characters ".
Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by The Apache Software Foundation, where it was formerly part of the Jakarta Project.
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
In computing, Java Web Start is a deprecated framework developed by Sun Microsystems that allows users to start application software for the Java Platform directly from the Internet using a web browser. The technology enables seamless version updating for globally distributed applications and greater control of memory allocation to the Java virtual machine.
pkg-config is a computer program that defines and supports a unified interface for querying installed libraries for the purpose of compiling software that depends on them. It allows programmers and installation scripts to work without explicit knowledge of detailed library path information. pkg-config was originally designed for Linux, but it is now also available for BSD, Microsoft Windows, macOS, and Solaris.
In software engineering, a WAR file is a file used to distribute a collection of JAR-files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages and other resources that together constitute a web application.
A portable application, sometimes also called standalone, is a program designed to operate without changing other files or requiring other software to be installed. In this way, it can be easily added to, run, and removed from any compatible computer without setup or side-effects.
In software development, CMake is cross-platform free and open-source software for build automation, testing, packaging and installation of software by using a compiler-independent method. CMake is not a build system itself; it generates another system's build files. It supports directory hierarchies and applications that depend on multiple libraries. It can invoke native build environments such as Make, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system.
The Java Class Loader, part of the Java Runtime Environment, dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The virtual machine will only load the class files required for executing the program. The Java run time system does not need to know about files and file systems as this is delegated to the class loader.
The Simple API for Grid Applications (SAGA) is a family of related standards specified by the Open Grid Forum to define an application programming interface (API) for common distributed computing functionality.
The Java Platform Module System specifies a distribution format for collections of Java code and associated resources. It also specifies a repository for storing these collections, or modules, and identifies how they can be discovered, loaded and checked for integrity. It includes features such as namespaces with the aim of fixing some of the shortcomings in the existing JAR format, especially the JAR Hell, which can lead to issues such as classpath and class loading problems.
java-gnome is a set of language bindings for the Java programming language for use in the GNOME desktop environment. It is part of the official GNOME language bindings suite and provides a set of libraries allowing developers to write computer programs for GNOME using the Java programming language and the GTK cross-platform widget toolkit.
Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface (JNI). JNA's design aims to provide native access in a natural way with a minimum of effort. Unlike JNI, no boilerplate or generated glue code is required.
The Java Development Kit (JDK) is a distribution of Java technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java Application Programming Interface (API). It is derivative of the community driven OpenJDK which Oracle stewards. It provides software for working with Java applications. Examples of included software are the Java virtual machine, a compiler, performance monitoring tools, a debugger, and other utilities that Oracle considers useful for Java programmers.
The Java Desktop Integration Components (JDIC) project provides components which give Java applications the same access to operating system services as native applications. For example, a Java application running on one user's desktop can open a web page using that user's default web browser, but the same Java application running on a different user's desktop would open the page in Opera . Initially the project supports features such as embedding the native HTML browser, programmatically opening the native mail client, using registered file-type viewers, and packaging JNLP applications as RPM, SVR4, and MSI installer packages. As a bonus, an SDK for developing platform-independent screensavers is included. Most of the features provided by JDIC were incorporated into the JDK starting with version 1.6. As a result, the development of the project has come to an end.
Dart is a programming language designed by Lars Bak and Kasper Lund and developed by Google. It can be used to develop web and mobile apps as well as server and desktop applications.