Some background; I’m quite used to PHP, and I always used something like ‘connect.ini’ where set all my variables to let the PHP script to the database (i.e. the DB URL, the password, the name, and so on); now, I’m taking same classes about Java iee, and the teacher wants us to use runnable jars and connect.bat files, linking them using the ‘String[] args’ in the main function. That is, you write your code and let the method to receive the variables to connect to the database, those variables are set in the main method where they were passed from the command arguments, the main call the method where the variables are needed and the program connects to the DB. the bat file is needed cause you put on it your settings plus the command plus the arguments (in form of environment variables); hope it was clear.
But I’m wondering if this is a good solution, and also if it’s an acceptable solution. My questions:
- Does this system work on Linux? I don’t believe so. Perhaps a shell script, so we are losing the portability of the code?
- Why not to use a simply ini file to be put in the resources?
- How would you rate a teacher who are asking to use this method to assign the variables to connect to the database?
- Am I wrong if I think he’s putting me in the wrong way when connecting to a database using external useful parameters?
There are a number of ways to supply parameters to the main method. E.G. for an app. launched via. Java Web Start, you would define those arguments in the JNLP launch file. To be a JWS app. means that the app.:
..all of which is probably significantly beyond the skills of your classmates right now.
You are right in believing that a .bat file is not optimal, since it is Windows specific. OTOH, it is one valid way to launch an app. when using Windows, and perhaps the teacher is looking to introduce you to more x-plat methods after this exercise.
My advice would be to be patient for the moment, but if the teacher introduces more exercises using .bat files to launch Java apps., ask them about other ‘more cross-platform’ ways to launch Java code.
And just a quick aside on .ini files. Java provides inbuilt support for
Propertiesfiles, which have a similar format to .ini, but I’m not sure if thePropertiesclass could parse an INI file.