打包程序优化,直接打成war包,包含容器,支持脚本运行

This commit is contained in:
thinkgem
2018-02-10 22:51:29 +08:00
parent c304dd05c1
commit d6f963b3be
17 changed files with 45 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ package com.jeesite.common.io;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -18,9 +19,6 @@ import javax.activation.MimetypesFileTypeMap;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import net.sf.jmimemagic.Magic;
import net.sf.jmimemagic.MagicMatch;
import org.apache.commons.io.Charsets; import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipEntry;
@@ -34,6 +32,9 @@ import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.collect.ListUtils; import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.lang.StringUtils; import com.jeesite.common.lang.StringUtils;
import net.sf.jmimemagic.Magic;
import net.sf.jmimemagic.MagicMatch;
/** /**
* 文件操作工具类 * 文件操作工具类
* 实现文件的创建、删除、复制、压缩、解压以及目录的创建、删除、复制、压缩解压等功能 * 实现文件的创建、删除、复制、压缩、解压以及目录的创建、删除、复制、压缩解压等功能
@@ -966,6 +967,8 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
} }
projectPath = file.toString(); projectPath = file.toString();
} }
} catch (FileNotFoundException e) {
;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -998,6 +1001,8 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
} }
webappPath = file.toString(); webappPath = file.toString();
} }
} catch (FileNotFoundException e) {
;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -16,6 +17,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import com.jeesite.common.collect.SetUtils;
import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.lang.ObjectUtils;
/** /**
@@ -29,8 +31,9 @@ public class PropertiesUtils {
// 默认加载的文件可通过继承覆盖若有相同Key优先加载后面的 // 默认加载的文件可通过继承覆盖若有相同Key优先加载后面的
public static final String[] DEFAULT_CONFIG_FILE = new String[]{ public static final String[] DEFAULT_CONFIG_FILE = new String[]{
"classpath:jeesite-core.yml", "classpath:jeesite.yml", "classpath:config/jeesite.yml",
"classpath:config/application.yml", "classpath:application.yml"}; "classpath:config/application.yml",
"classpath:application.yml"};
private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class); private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
@@ -45,7 +48,16 @@ public class PropertiesUtils {
releadInstance(); releadInstance();
} }
public static void releadInstance(){ public static void releadInstance(){
INSTANCE = new PropertiesUtils(DEFAULT_CONFIG_FILE); Set<String> configFiles = SetUtils.newLinkedHashSet();
Resource[] resources = ResourceUtils.getResources("classpath*:/config/jeesite-*.*");
for(Resource resource : resources){
configFiles.add("classpath:/config/"+resource.getFilename());
}
for (String configFile : DEFAULT_CONFIG_FILE){
configFiles.add(configFile);
}
logger.debug("Loading jeesite config: {}", configFiles);
INSTANCE = new PropertiesUtils(configFiles.toArray(new String[configFiles.size()]));
} }
} }

View File

@@ -79,8 +79,12 @@ public class ResourceUtils extends org.springframework.util.ResourceUtils {
*/ */
public static Resource[] getResources(String locationPattern){ public static Resource[] getResources(String locationPattern){
try { try {
return new PathMatchingResourcePatternResolver() Resource[] resources = new PathMatchingResourcePatternResolver()
.getResources(locationPattern); .getResources(locationPattern);
// System.out.println("===========\n===========");
// System.out.println(locationPattern + " : " + resources.length);
// System.out.println("===========\n===========");
return resources;
} catch (IOException e) { } catch (IOException e) {
throw ExceptionUtils.unchecked(e); throw ExceptionUtils.unchecked(e);
} }

View File

@@ -14,6 +14,6 @@
</root> </root>
<!-- Framework level setting --> <!-- Framework level setting -->
<include resource="logger-core.xml"/> <include resource="config/logger-core.xml"/>
</configuration> </configuration>

View File

@@ -100,7 +100,9 @@
</includes> --> </includes> -->
<archive> <archive>
<manifest> <manifest>
<!-- caution: add directory entries --> <!-- Add directory entries -->
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
</manifest> </manifest>
</archive> </archive>

View File

@@ -15,7 +15,7 @@
<property name="context-root" value="jeesite-web"/> <property name="context-root" value="jeesite-web"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/> <wb-resource deploy-path="/" source-path="src/main/webapp"/>
<property name="java-output-path" value="/src/main/webapp/WEB-INF/classes"/> <property name="java-output-path" value="/src/main/webapp/WEB-INF/classes"/>
<property name="component.exclusion.patterns" value="userfiles/**,test/**"/> <property name="component.exclusion.patterns"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>

View File

@@ -14,20 +14,12 @@ rem echo.
cd %~dp0 cd %~dp0
cd ../ cd ../
title %cd%
set currPath=%cd% title %cd%
rem set MAVEN_OPTS=%MAVEN_OPTS% -Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m rem set MAVEN_OPTS=%MAVEN_OPTS% -Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m
set MAVEN_OPTS=%MAVEN_OPTS% -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m set MAVEN_OPTS=%MAVEN_OPTS% -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
if exist "../package/pom.xml" (
cd ../package
call mvn clean install -Dmaven.test.skip=true -Ppackage -U
)
cd %currPath%
call mvn clean spring-boot:run -U call mvn clean spring-boot:run -U
pause pause

View File

@@ -5,7 +5,7 @@ rem *
rem * Author: ThinkGem@163.com rem * Author: ThinkGem@163.com
rem */ rem */
echo. echo.
echo [信息] 运行Web工程。 echo [信息] 打包Web工程运行Web工程。
echo. echo.
rem pause rem pause
rem echo. rem echo.
@@ -14,12 +14,17 @@ rem echo.
cd %~dp0 cd %~dp0
cd ../ cd ../
call mvn clean package spring-boot:repackage -Dmaven.test.skip=true -U
title %cd% title %cd%
rem set JAVA_OPTS= -Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m rem set JAVA_OPTS= -Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m
set JAVA_OPTS= -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m set JAVA_OPTS= -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m
cd target/ cd target/
java -jar jeesite-web.war call unzip -n jeesite-web.war -d jeesite-web
cd jeesite-web
call java org.springframework.boot.loader.WarLauncher
pause pause

View File

@@ -15,4 +15,3 @@ server:
debug: true debug: true

View File

@@ -9,7 +9,7 @@ jdbc:
# Mysql 数据库配置 # Mysql 数据库配置
type: mysql type: mysql
driver: com.mysql.jdbc.Driver driver: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jeesite4?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull url: jdbc:mysql://127.0.0.1:3306/jeesite4?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
username: root username: root
password: 123456 password: 123456
testSql: SELECT 1 testSql: SELECT 1

View File

@@ -56,6 +56,6 @@
</root> </root>
<!-- Framework level setting --> <!-- Framework level setting -->
<include resource="logger-core.xml"/> <include resource="config/logger-core.xml"/>
</configuration> </configuration>

View File

@@ -23,8 +23,8 @@ public class InitGenData extends com.jeesite.modules.gen.db.InitGenData {
@Test @Test
public void initGenData() throws Exception{ public void initGenData() throws Exception{
createGenTable(); createGenTable();
initGenTreeData();
initGenTestData(); initGenTestData();
initGenTreeData();
} }
} }