Add something to the java classpath

Add something to the java classpath

Problem Description:

I have a jar-File, which I want to add to the classpath, so I ran java -cp ".;C:Pathtomymagicaljarfile.jar;.someotherdirectory" MyClass

The Problem is: I use some import-commands in my class, an Java doesn’t find them anymore, because I replaced the classpath. I want just add two elements to the Path. How is this posible under Windows?

Solution – 1

https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
specifies:

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

So, to add to that default, include the CLASSPATH environment variable in your invocation:

java -cp ".;C:Pathtomymagicaljarfile.jar;.someotherdirectory;%CLASSPATH%"
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject