Solve the problem of the path of the configuration file cannot be obtained after the project hits the jar package

Source: Internet
Author: User

Today in the development of a Java project, requires reading the information in the configuration file, began to write the absolute path, when the project hit jar package will not find the configuration file, back in the online when a method, the problem finally solved, take out to share with you.

public class Smbconfig {
SMB Message Parameters
public static String Smb_sender = ""; SMB Message Sender
public static String Smb_exchange = ""; SMB Message Group
public static String Smb_serverip = ""; SMB Server-side IP
public static String Smb_serverport = ""; SMB Service port number


static {
InputStream in = SMBConfig.class.getClass (). getResourceAsStream ("/config/config.properties");
Properties P = new properties ();
try {
P.load (in);
} catch (IOException e) {
E.printstacktrace ();
}
SMB Message Parameters
Smb_sender = P.getproperty ("Smb.sender"). ToString (). Trim ();
Smb_exchange = P.getproperty ("Smb.exchange"). ToString (). Trim ();
Smb_serverip = P.getproperty ("Smb.smbserip"). ToString (). Trim ();
Smb_serverport = P.getproperty ("Smb.smbserport"). ToString (). Trim ();
}
}

Solve the problem of the path of the configuration file cannot be obtained after the project hits the jar package

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.