"Deep Java" program packaged into a jar package to run and read external configuration files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.