0

Currently I'm building a small personal project in Java which is a simple file server. I've implemented basic internationalization with usage of ResourceBundle. I'm using .properties files to store messages in different languages.

Till now I was using Vscode built-in java compilation process which was copying .properties files into its corresponding directory in the output. However now I'd like to write a build script for that project.

My command looks like this: javac -d ./bin -cp ./src ./src/**/*.java.

This command however doesn't take .properties files into account. I searched web whether javac has ability to somehow process/include this files into output but found no answer. I know I can use Maven or Ant, but I'd like to make this project without usage of additional tools.

USHKA
  • 647
  • 4
  • 18
  • You're wasting time not using a build tool. Resource files (such as .properties files) are handled easily with something like Maven. – stdunbar Sep 12 '22 at 21:14
  • I'll surely be using build tools soon and probably in every next project I'll create. I just want to test and sum up my current Java Core knowledge building this project using only indispensable tools. I think that understanding how things work is always profitable. – USHKA Sep 12 '22 at 21:41
  • 1
    Then you'll need to manually copy the `.properties` files to what appears to be your `./bin` directory. It's unclear if these need to be in packages but, if so, they need to be copied to the appropriate subdirectory under `./bin`. Build tools are indispensable to professionals. – stdunbar Sep 12 '22 at 22:09
  • The adoption by build tools of the use of a "resources" directory was a poor decision, in my opinion. It would have been been quite natural and less contrived for them to treat any non-Java file under the "java" directory as class resource files. – erickson Mar 01 '23 at 16:34

2 Answers2

1

Answering to my own question, but maybe someone will find this useful one day. In short javac always compiles .java files producing .class files. There is no way that it could process some other file (source: How to set the output files when compiling with javac).

Long story short if you want to include resources, images, text files, anything that is not .java file in your output, and don't want to use build tools, you have to copy it manually or use cp command in your build script.

USHKA
  • 647
  • 4
  • 18
-1

This is why java .jar files were invented. You want to create a .jar file and include your properties file, like so:

jar cvfm myjarname.jar MANIFEST.MF src/*.class my.properties

john k
  • 6,268
  • 4
  • 55
  • 59