Importing has nothing to do with loading classes or setting CLASSPATH.

Try this:

java -cp .;../lib/* Generator

Using the dot '.' as the first entry in the CLASSPATH assumes that the Generator.class file exists in the directory from which you're running java, and /lib is one level up from that directory. Adjust as needed if both of these are not correct.

Answer from duffymo on Stack Overflow
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2011 โ€บ 01 โ€บ how-classpath-work-in-java.html
How to Set Classpath for Java on Windows and Linux? Steps and Example
6. In Unix or Linux operating system, Java Classpath contains names of the directory with a colon โ€œ:โ€ separated, On Windows Java Classpath will be semicolon โ€œ;โ€ separated while if you defined java classpath in Manifest file those will ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ java classpath syntax in linux vs. windows
Java Classpath Syntax in Linux vs. Windows | Baeldung
January 8, 2024 - However, if we take a closer look at the Java man page on Linux, it says the classpath separator is the semicolon (;). For example, the man page of the java command from the latest(ver.17) OpenJDK shows:
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ java examples โ€บ java โ€“ set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS. The classpath is the list of directory locations that the Java runtime environment searches for the classes and other resource ...
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ technotes โ€บ tools โ€บ unix โ€บ classpath.html
2 Setting the Class Path
April 21, 2026 - The class path is the path that the Java Runtime Environment (JRE) searches for classes and other resource files. ... The class search path (class path) can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable.
๐ŸŒ
Michigan State University
web.pa.msu.edu โ€บ reference โ€บ jdk-1.2.2-docs โ€บ tooldocs โ€บ solaris โ€บ classpath-linux.html
Setting the class path
For very special cases, both java and javac have options that let you change the path they use to find their own class libraries. The vast majority of users will never to need to use those options, however. In general, you will want to use the -classpath command-line option, as explained in the previous section.
๐ŸŒ
Chilkat
chilkatsoft.com โ€บ java-classpath-Linux.asp
Java JAR Archives and classpath on Linux
String classpath = System.getProperty("java.class.path"); System.out.println(classpath); Modify the CLASSPATH environment variable to also include the directory containing the JAR archive. In csh, the CLASSPATH environment variable is modified with the setenv command.
Find elsewhere
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Classpath
Classpath - Wikipedia
May 30, 2026 - 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.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java basics โ€บ java classpath
How to set CLASSPATH in Java - HowToDoInJava
February 23, 2023 - Use the following command to set the classpath for different requirements. Letโ€™s say we have a folder named dependency where JAR files and other classes are placed. Below syntax examples will add single jar file in classpath. //WINDOWS $ set CLASSPATH=.;C:\dependency\framework.jar //Linux/Unix $ export CLASSPATH=.:/dependency/framework.jar
๐ŸŒ
Mcmaster
cas.mcmaster.ca โ€บ ~lis3 โ€บ javatutorial โ€บ Classpath.htm
java tutorial, CLASSPATH, -classpath, -d
After compile and stored all classes ... before. The steps would be 1. ... java TimeTest<cr>. java has -classpath option, which allows you to run a bytecode files in a different directory....
Top answer
1 of 16
1340

Using Java 6 or later, the classpath option supports wildcards. Note the following:

  • Use straight quotes (")
  • Use *, not *.jar

Windows

java -cp "Test.jar;lib/*" my.package.MainClass

Unix

java -cp "Test.jar:lib/*" my.package.MainClass

This is similar to Windows, but uses : instead of ;. If you cannot use wildcards, bash allows the following syntax (where lib is the directory containing all the Java archive files):

java -cp "$(printf %s: lib/*.jar)"

(Note that using a classpath is incompatible with the -jar option. See also: Execute jar file with multiple classpath libraries from command prompt)

Understanding Wildcards

From the Classpath document:

Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

A class path entry that contains * will not match class files. To match both classes and JAR files in a single directory foo, use either foo;foo/* or foo/*;foo. The order chosen determines whether the classes and resources in foo are loaded before JAR files in foo, or vice versa.

Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo, not in foo/bar, foo/baz, etc.

The order in which the JAR files in a directory are enumerated in the expanded class path is not specified and may vary from platform to platform and even from moment to moment on the same machine. A well-constructed application should not depend upon any particular order. If a specific order is required then the JAR files can be enumerated explicitly in the class path.

Expansion of wildcards is done early, prior to the invocation of a program's main method, rather than late, during the class-loading process itself. Each element of the input class path containing a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory foo contains a.jar, b.jar, and c.jar, then the class path foo/* is expanded into foo/a.jar;foo/b.jar;foo/c.jar, and that string would be the value of the system property java.class.path.

The CLASSPATH environment variable is not treated any differently from the -classpath (or -cp) command-line option. That is, wildcards are honored in all these cases. However, class path wildcards are not honored in the Class-Path jar-manifest header.

Note: due to a known bug in java 8, the windows examples must use a backslash preceding entries with a trailing asterisk: https://bugs.openjdk.java.net/browse/JDK-8131329

2 of 16
287

Under Windows this works:

java -cp "Test.jar;lib/*" my.package.MainClass

and this does not work:

java -cp "Test.jar;lib/*.jar" my.package.MainClass

Notice the *.jar, so the * wildcard should be used alone.


On Linux, the following works:

java -cp "Test.jar:lib/*" my.package.MainClass

The separators are colons instead of semicolons.

๐ŸŒ
LinuxQuestions.org
linuxquestions.org โ€บ questions โ€บ linux-newbie-8 โ€บ set-java-classpath-on-linux-914077
set java classpath on linux
November 17, 2011 - Hello! I'm a new user in Linux. I'm using opensuse 11.2, but i don't know how to set path to java. The problem in console: Code: Exception in thread &q
Top answer
1 of 3
13

First, in general, setting the env var CLASSPATH usually causes more problems than it solves -- since not all app's want/need the same classpath, & often break when undesired or even unneeded jars are included in the classpath. A java app should only include the minimum number of jars it requires, no more, no less.

When you have specific, individual apps that do require that the classpath be set, then usually the command-line option is preferred: java -cp path1:path2:.... Desktop icons can have their command altered to include these options, or shell scripts can be modified to include these options.

That being said (and since there are always exceptions to the rule), then depending on the version of java (this requres java 6 or later), you can specify that a whole directory of jars be added to the classpath by adding a "*" at the end of a directory; e.g, the following:

 /dir1/foo.jar:/dir2/dir3:/dir5/dir6/*:etc...

Means:

  • /dir1/foo.jar - (the single jar) will be added to the classpath;
  • /dir2/dir3 - all un-jar'd classes in this directory will be added to the classpath (must be in proper package structure; e.g, com.my.Foo.class must be in /dir2/dir3/com/my/Foo.class)
  • /dir5/dir6/* - all jars in this directory (i.e., /dir5/dir6/*.jar) will be added to the classpath. Note that this "*" isn't a wildcard (you can't use f*.jar or even *.jar); it's a special character indicating "add all jars"

In general, if you have to add a whole directory of jars to the application's classpath, the app was not bundled correctly. Rather, the app should have a manifest containing the list of jars it depends on. Or at the very least, only one jar should be added to your classpath, and that jar can have in its manifest the whole list of jars in some subdirectory.

2 of 3
4

if you want to set classpath permanently then 1) find out where java is installed.. you may use "whereis java" openjdk-7/6 is in /usr/lib/jvm/.....

2) we need to set up CLASSPATH in /etc/environment

  sudo gedit /etc/environment

3) add the following likes .. ( DONT LEAVE ANY SPACES WHILE TYPING)(customize according to your java version and installation) (this home path is for open jdk 7)

   JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"

   export JAVA_HOME

   CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib:/home/laptop/Desktop/a2"

   export CLASSPATH

separate directory by ":"

๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2011 โ€บ 01 โ€บ how-classpath-work-in-java.html
Javarevisited: How to Set Classpath for Java on Windows and Linux? Steps and Example
6. In Unix or Linux operating system, Java Classpath contains names of the directory with a colon โ€œ:โ€ separated, On Windows Java Classpath will be semicolon โ€œ;โ€ separated while if you defined java classpath in Manifest file those will ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ different-ways-to-set-a-classpath-in-java
Different Ways to Set a Classpath in Java - GeeksforGeeks
July 23, 2025 - If we want to access classpath for all command lines, we must set the classpath command option.
๐ŸŒ
Dkessner
dkessner.github.io โ€บ ProcessingLibraryExamples โ€บ classpath.html
Setting the Java CLASSPATH | ProcessingLibraryExamples
export CLASSPATH=".:/Applications/Processing.app/Contents/Java/core/library/*" If you are using an IDE, you will want to set the CLASSPATH in the project or application settings. If you are running your programs from the command line, you will want to include the above export line in a script (e.g.