0

I have the following package:

  • project
    • images
      • 1.jpg
    • audio
      • 1.mid
    • src
      • main.java
      • myClass.java

This is the package folder hierarchy of my project. When using Eclipse, I can load the image 1.jpg by giving the relative path "images/1.jpg" or "./images/1.jpg". However, if I am to compile all the .java files in the src folder using the command "javac src/*.java" and run main, the program tells me that 1.jpg is not found. I have to change the path to image file in my code to "../images/1.jpg" for it to work. It therefore seems that in Eclipse, all the .java files think they are in the same folder as the "images" folder, which reduces a lot of work for me. How do I achieve the same without using Eclipse? (Using command line compilation)

user454450
  • 21
  • 2
  • If it is working in eclipse, it should work after compilation too. – Suresh Atta Sep 17 '16 at 18:46
  • Eclipse has nothing to do with that. If you type `ls images/1.jpg`, you'll get the info about the image only if you're inside the project directory, because that's a relative path. So if you're inside src, `images/1.jpg` points to nothing. The same goes for java: if it opend a file using a relative path, you have to be in the correct directory when executing the java command. Unrelated, but never use the defaut package. never. – JB Nizet Sep 17 '16 at 18:47
  • Simple advise: **don't** do that. Do not use the default package. There is almost not benefit in not using some simple package. Just a lot of potential for things to wrong. And: read about java naming conventions. Java classes names go UpperCase. – GhostCat Sep 17 '16 at 18:57
  • Possible duplicate of [javac option to compile all java files under a given directory recursively](http://stackoverflow.com/questions/6623161/javac-option-to-compile-all-java-files-under-a-given-directory-recursively) – Paul Sweatte Oct 14 '16 at 15:11

0 Answers0