问题
My project directory structure is something like this: ProjectName/coursesRegistration/src/coursesRegistration/util
When I do "import coursesRegistration.util.FileProcessor;
" in Eclipse it works but when I try this on UNIX (using command line compilation) it gives me an error saying
"error: package coursesRegistration.util does not exist".
Maybe I am missing something very basic, does anyone know what may be the problem?
回答1:
If you're trying to do command-line compilation, this is probably the issue.
You're running the javac
command outside of the src
folder. This is an issue because java's package system expects to find class coursesRegistration.util.FileProcessor
in ./coursesRegistration/util/FileProcessor.java
, where the current directory is where you are when you run javac
. The way to fix this is to pass the path to the src
directory to the --class-path
option. For example, running the compiler from the ProjectName
directory:
javac --class-path coursesRegistration/src ...
Also, just so you know, you will have to be in the src
directory to run the program itself. Eclipse handles all this behind the scenes, so I would either use Eclipse, or the command line, but not both.
回答2:
Thank you guys! I just found out running "ant -buildfile build.xml" and then "ant run -buildfile build.xml" does the magic for you!
来源:https://stackoverflow.com/questions/52357602/java-package-does-not-exist-error-in-unix