package util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
**/
public class Constants extends Properties{
private static final long serialVersionUID = 1L;
private static Properties p = null;
static {
try {
p = new Properties();
//读取jar包中的配置文件
//InputStream fis = Constants.class.getClassLoader().getResourceAsStream("../resource/config.properties");
InputStream fis = Constants.class.getResourceAsStream("../config.properties");
try {
p.load(fis);
} catch (final IOException e) {
e.printStackTrace();
throw new NullPointerException("Failed to load config file: "
+ "config.properties" + ", error: " + e.getMessage());
} finally {
if (fis != null) {
try {
fis.close();
} catch (final IOException e) {
// do nothing
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String MYSQLDRIVER = p.getProperty("MYSQL.DRIVER") ;
public static String MYSQLDRIVER_URL = p.getProperty("MYSQL.DRIVER_URL") ;
public static String MYSQLUSER = p.getProperty("MYSQL.USER") ;
public static String MYSQLPASS = p.getProperty("MYSQL.PASS") ;
public static void main(String[] args){
System.out.println(MYSQLDRIVER);
}
}
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
**/
public class Constants extends Properties{
private static final long serialVersionUID = 1L;
private static Properties p = null;
static {
try {
p = new Properties();
//读取jar包中的配置文件
//InputStream fis = Constants.class.getClassLoader().getResourceAsStream("../resource/config.properties");
InputStream fis = Constants.class.getResourceAsStream("../config.properties");
try {
p.load(fis);
} catch (final IOException e) {
e.printStackTrace();
throw new NullPointerException("Failed to load config file: "
+ "config.properties" + ", error: " + e.getMessage());
} finally {
if (fis != null) {
try {
fis.close();
} catch (final IOException e) {
// do nothing
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String MYSQLDRIVER = p.getProperty("MYSQL.DRIVER") ;
public static String MYSQLDRIVER_URL = p.getProperty("MYSQL.DRIVER_URL") ;
public static String MYSQLUSER = p.getProperty("MYSQL.USER") ;
public static String MYSQLPASS = p.getProperty("MYSQL.PASS") ;
public static void main(String[] args){
System.out.println(MYSQLDRIVER);
}
}