Java “package does not exist” error in UNIX

↘锁芯ラ 提交于 2021-01-28 03:46:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!