In the process of reading any questions, welcome to communicate together
Email: [email protected]
QQ:1494713801
First, the program settings
The main method of Java has an initialization parameter of args, which is represented as the path to the configuration file, with the following code:
1 Public Static void Main (string[] args) {2 loadconf (args[0]); 3 }
1 Public Static voidloadconf (String Path)throwsException {2Properties props =NewProperties ();3InputStream in =NewFileInputStream (path);4 props.load (in);5Fromdb = Props.getproperty ("Fromdb");6Fromdbuser = Props.getproperty ("Fromdbuser");7Fromdbpassword = Props.getproperty ("Fromdbpassword");8 if(Stringutils.isempty (Fromdb)) {9String errmsg = "Fromdb or tables is null";Ten Logger.error (errmsg); One Throw NewException (errmsg); A } -}
Second, packaging procedures
Package The program as a jar through the export of Eclipse (uncheck the profile option during packaging)
Third, run the jar package
The command to execute the JAR package into the external configuration file under Linux (for example, enter D: The same reason, Java-jar Xxx.jar config.properties):
/opt/pasier/config.properties
The args can be used to load the configuration file path of the Red section above.
Reference Link: http://www.cnblogs.com/enshrineZither/p/3449861.html
"Deep Java" program packaged into a jar package to run and read external configuration files