一、项目简介
本项目通过运行批处理命令单独运行jar或class文件,来执行特殊处理的小程序,无需依赖任何容器,简单独立,方便部署扩展,一般应用场景是小工具、业务应用的拆分、快速开发实施、小白用户(简化部署实施)等
二、代码部分
1. 启动脚本&部署脚本
app_startup.bat内容@echo off@b@cd ..@b@set APP_HOME=%cd%@b@echo %APP_HOME% @b@ @b@::set JAVA_HOME=%APP_HOME%\jdk@b@echo %JAVA_HOME% @b@@b@set CLASSPATH=.;%APP_HOME%\lib\classes\;%APP_HOME%\lib\commons-logging-1.0.4.jar;%APP_HOME%\lib\log4j-1.2.16.jar;%JAVA_HOME%\jre\lib\rt.jar@b@@b@cd bin@b@::start "" "%JAVA_HOME%\bin\javaw.exe" -classpath "%APP_HOME%\lib\classes\" -Djava.ext.dirs="%JAVA_HOME%\lib\ext";"%APP_HOME%\lib\ext" -Xms256m -Xmx512m com.xwood.boot.Bootstrap.Bootstrap@b@java.exe -Xms128m -Xmx800m com.xwood.boot.Bootstrap@b@@pause
target.bat内容@echo off @b@title deploy target@b@cd ..@b@set APP_HOME=%cd%@b@echo %APP_HOME% @b@cd bin@b@@b@echo 正在deploy,请稍等...... @b@@b@xcopy %APP_HOME%\bin %APP_HOME%\target\xwood-boot\bin /s /e /y /f@b@@b@xcopy %APP_HOME%\lib %APP_HOME%\target\xwood-boot\lib /s /e /y /f@b@@b@xcopy %APP_HOME%\logs %APP_HOME%\target\xwood-boot\logs /s /e /y /f@b@ @b@@b@echo deploy 完成! @b@echo. & pause @b@exit
2. Bootstrap启动类import java.util.concurrent.ExecutorService;@b@import java.util.concurrent.Executors;@b@@b@import org.apache.commons.logging.Log;@b@import org.apache.commons.logging.LogFactory;@b@@b@import com.xwood.boot.configure.ConfigureMgr;@b@import com.xwood.boot.parse.FileParseEngine;@b@@b@public class Bootstrap {@b@@b@ /** 配置引擎执行时间 */@b@ private static int working_engine_num = Integer.parseInt(ConfigureMgr.getString("process.cpu"));@b@@b@ private static ExecutorService executor = Executors.newFixedThreadPool(working_engine_num);@b@@b@ private static Log logger = LogFactory.getLog(Bootstrap.class);@b@ //public static Logger logger = Logger.getLogger(Bootstrap.class.getName());@b@@b@ public static void main(String[] args) {@b@@b@ logger.info("系统服务已启动,请等待执行...");@b@ int tid = 1;@b@@b@ while (working_engine_num-- > 0) {@b@ logger.info("线程" + tid + "资源加入处理..");@b@ executor.execute(new FileParseEngine());@b@ tid++;@b@ }@b@@b@ }@b@@b@}
3. log4j.properties配置内容log4j.rootLogger=info,stdout,error,file@b@@b@log4j.appender.stdout=org.apache.log4j.ConsoleAppender@b@log4j.appender.stdout.layout=org.apache.log4j.PatternLayout@b@log4j.appender.stdout.layout.ConversionPattern=[xwood-boot] [%t] %d - %c -%-4r [%t] %-5p%c %x - %m%n@b@@b@log4j.appender.file=org.apache.log4j.RollingFileAppender@b@log4j.appender.file.MaxFileSize=4MB@b@log4j.appender.file.MaxBackupIndex=9@b@@b@#- File to log to and log format@b@log4j.appender.file.File=../logs/xwood-boot-info.log @b@log4j.appender.file.layout=org.apache.log4j.PatternLayout @b@log4j.appender.file.layout.ConversionPattern=[xwood-boot] [%t] %d - %c -%-4r [%t] %-5p%c %x - %m%n@b@ @b@@b@log4j.logger.error=error@b@log4j.appender.error=org.apache.log4j.DailyRollingFileAppender@b@log4j.appender.error.layout=org.apache.log4j.PatternLayout@b@log4j.appender.error.layout.ConversionPattern=[xwood-boot] [%t] %d - %c -%-4r [%t] %-5p%c %x - %m%n@b@log4j.appender.error.datePattern='.'yyyy-MM-dd@b@log4j.appender.error.Threshold = ERROR @b@log4j.appender.error.append=true@b@log4j.appender.error.File=../logs/xwood-boot-error.log