I have a small java project. And i want to keep a structure in how the files are organized in my project folder.
There are 3 folders: bin/, res/ and src/.
In src are all source files.
In res are some resources like textfiles to be printed are files that are saved during runtime.
And in bin is where all the binarys should be.
I found out, that i can compile my sourcefiles with the -d argument to the bin folder.
javac -d bin src/*.java
But I can’t run java bin/Main from my project folder it gives me a classnotfound error.
(Going in bin and then run java Main works. why??)
Second problem is, that res files are only accessible when res/ is in bin/. I want it kind of like in Eclipse. In the sourcecode files in res/ are used like the executor is in the project folder.
I hope you understand what i’m trying to do. And thanks for any help!
Java requires the
.classfiles to be locatable from the classpath root directory. So if your classpath is., then the classcom.mycompany.MyClassshould be at./com/mycompany/MyClass.class. So to run your files from your base directory, set the classpath by giving the-cp bincommand-line argument tojava.How are you trying to get to the
resfiles? If you use the-cptrick above, you should be fine with something likenew FileReader("res/file1.txt"). If you run in thebinfolder, you would neednew FileReader("../res/file1.txt")