一、各环境修改tomcat目录下配置文件进行配置
通过修改catalina.sh配置(TOMCAT_HOME/bin)
进入catalina.sh找到
JAVA_OPTS='-Xms512m -Xmx512m -XX:PermSize=256M -XX:MaxNewSize=256m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8'
JAVA_OPTS的值插入以下语句
在后面加上 -Dglobal.config.path=/usr/local/jconfig
红色字体根据配置文件所在的位置修改
《后台开发人员》本地通过idea启动包时,需要添加以下配置
使用idea的maven启动,需要在edit configurations -Runner中添加Environment variables:global.config.path=E:/maps-jushi/project-setting/dev;
红色字体修改为项目路径,如图
以上方法不行,则采用以下方法:
在parameters的command line内增加“-Dglobal.config.path=E:\gitworkplace\maps-jushi\project-setting”
clean -Pdev tomcat7:run -Dmaven.tomcat.port=8081 -Dglobal.config.path=E:\gitworkplace\maps-jushi\project-setting
二、java的文件SystemProperties写法
package com.zdnst.common.infra.utils; import java.util.Properties; /** * 读取web.properties配置文件 * @author zhongyq * @version 1.0.0, 2013-3-19 */ public class SystemProperties { // the properties object private static Properties props; /** * This method returns the property values, if found. It loads the properties * from the map properties file if not already loaded. * @param property the property whose value is requested for * @param def the default value to return if property not found * @return String retVal the value returned */ public static String getProperty(String property, String def) { String retVal = null; getProperties(); if(props != null) retVal = props.getProperty(property, def).trim(); else retVal = def; return retVal; } /** * @describe: 根据给定的KEY获取配置信息,没有默认返回空字符串 * @param key * @return * @author:kui.he * @time:2014年9月22日下午12:04:25 */ public static String getProperty(String key){ return getProperty(key,""); } /** * sets the property for the given key & value * @param strKey String Key * @param strValue String Value * @return void * **/ public static void setProperty(String strKey, String strValue) { if(props != null) props.setProperty(strKey, strValue); } /** * This method loads the properties object and returns it. * @return Properties the loaded property object, else null */ public static Properties getProperties() { if(props == null) { try { loadProperties("resources.properties"); } catch(Exception exc) { System.err.println(exc.getMessage()); props = null; } } return props; } /** * This method loads the Properties object from the Map Properties file * @param file the configuration file */ public static void loadProperties(String file) throws Exception { props = loadPropertiesFile(file); } /** * This method loads a Properties object and returns it * @param file the configuration file to load */ public static Properties loadPropertiesFile(String file) throws Exception { // String proFile = ConfigUtils.getInstance().getClassPath()+file; String path = System.getProperty("global.config.path") == null ? ConfigUtils.getInstance().getClassPath() : System.getProperty("global.config.path") ; String proFile = path +"/"+file; //System.out.println(proFile); return ConfigUtils.loadProperties(proFile); // Properties retVal = new Properties(); // String url=SystemProperties.class.getClassLoader().getResource("/")+file; // System.out.println("url:"+url); // InputStream in = SystemProperties.class.getClassLoader().getResourceAsStream(file); // if(in != null) // retVal.load(in); // in.close(); // return retVal; } /** * 返回类目录路径,如:D:\tools\apache-tomcat-7.0.42\webapps\maps1.1\WEB-INF\classes\ * * @return * @author:kaiqiang.wu * @time:2015年11月18日上午10:59:22 */ public static String getClassPath(){ return SystemProperties.class.getClassLoader().getResource("").getPath(); } public static void main(String[] args) { System.out.println(SystemProperties.getClassPath()); } }
三、application-context.xml
<context:property-placeholder location="file:${global.config.path}/resources.properties"/>
四、将配置文件拉取到相应位置:
usr/local/jconfig/resources.properties拉取配置文件到相应的路径;