Last active
August 29, 2015 14:23
-
-
Save qfrank/9c09c3728cd8aac017b2 to your computer and use it in GitHub Desktop.
tomcat virtual mapping xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static createVirtualMappingXml(){ | |
if(Environment.current != Environment.DEVELOPMENT){ | |
def catalinaHome = System.getenv('CATALINA_HOME') | |
if(!catalinaHome){ | |
catalinaHome = System.getProperty("catalina.base") | |
} | |
if(!catalinaHome){ | |
throw new RuntimeException("找不到环境变量CATALINA_HOME") | |
} | |
// 生成虚拟目录映射文件 | |
def configDir = new File("${catalinaHome}/conf/Catalina/localhost") | |
if(!configDir.exists()){ | |
if(configDir.mkdirs()){ | |
throw new RuntimeException("创建虚拟映射目录失败,路径为${configDir.absolutePath}") | |
} | |
} | |
def context = Holders.config.tomcat.virtual.mapping.static.context | |
def docBase = Holders.config.tomcat.virtual.mapping.static.baseDir | |
def xml = new File("${configDir.absolutePath}/${context}.xml") | |
if(!xml.exists()){ | |
xml.withWriterAppend{ | |
it.write("""<?xml version="1.0" encoding="UTF-8"?> | |
<Context antiResourceLocking="false" reloadable="true" docBase="${docBase}"/> | |
""") | |
} | |
println ("创建虚拟目录映射文件:${xml.absolutePath}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment