I am having a problem using the custom jar libraries (algs4.jar/stdlib.jar from http://algs4.cs.princeton.edu/home/) with the command prompt. I added the libraries to the IntelliJ classpath setting (project sturcture -> SDKs -> classpath) and am able to use their classes with no problems using IntelliJ.
However, I also want to be able to use these libraries in the command prompt. Even though I had no CLASSPATH variable set in my Windows settings I’ve been able to use javac/java in cmd with no problems when using the standard java libraries. (Probably because IntelliJ sets the CLASSPATH for all the standard libraries on every startup/compile to work systemwide). However, even after adding the 2 jars to the IntelliJ classpath setting, I wasn’t able to use “javac” in cmd. I then created the CLASSPATH variable in windows settings, and added the jars to them. After this I was able to compile with javac with no problems. However, when I try to run the program in cmd, I get this:
“Error: Could not find or load main class “.
I get this error whenever I uses ANY of the jar libraries, including the standard ones, with which I didn’t have problems prior to setting the Windows CLASSPATH. I guess what happens is once I set my own CLASSPATH this overrides the classpath set by intelliJ. When I removed the CLASSPATH, I was once again able to compile and run the standard libraries in cmd, but not the 2 custom libraries.
Please help!
You should make these libraries a part of the project by adding them to the module dependencies as a library instead of the JDK, then you can produce an artifact jar file that will have all the dependencies inside or near the jar and referenced via the jar manifest file classpath. See also the artifacts help section.