I've just come back to fix some bugs in a small program that I've written, and now I can't compile because a package doesn't exist (according to javac).
As far as I know, I haven't changed anything in my class path, or the contents of my directories. I don't know if there have been any Java updates in between.
In my root directory, I have the four Java files that comprise my program. They don't have any package ascribed to them. Additionally, I have the directory structure org\apache\commons\cli in the root directory which contains the CLI java files from the Apache Commons. The Apache files do have a package ascribed that mirrors the directory structure in which they lie.
If I issue the command javac -verbose -d build CommandLine.java, it fails with
CommandLine.java:28: package org.apache.commons.cli does not exist
import org.apache.commons.cli.*;
^
CommandLine.java is the entry point of the program.
There is no attempt by the compiler to compile the CLI files, and if I compile them beforehand, the failure still takes place. Also, the CLI is also available in my classpath.
I am running javac 1.6.0_12.
What can I do/try?
.
EDITED FOR ANSWER:
As accepted below, I altered the compilation command to be:
javac -verbose -d build -classpath . CommandLine.java
Now it works. Don't know why it did before, and why it stopped now though...
.
EDITED FOR CAUSE OF PROBLEM
I installed a program that also used the CLASSPATH to run its own things. It changed the CLASSPATH that belonged to the user, but left the global one alone. I re-added the java classpath things back in and it works again!
Did you unpack that Apache JAR and add the .class files to your application? Why didn't you just add the JAR to your CLASSPATH?
You should not be depending on a CLASSPATH environment variable. Better to use the -classpath option for javac.exe when you compile and java.exe when you run.
Unless it's a typo, notice you said com\apache\commons\cli but the import wants org.apache.commons.cli -- org vs com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With