标签:文件中 maven3 很多 exp http xms span artifact 文件类型
文章首发于个人博客:https://yeyouluo.github.io/
见 《5 参考》一节。
eclipse mars2 + Maven3.3.9
POM如下:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2 <modelVersion>4.0.0</modelVersion> 3 <groupId>com.yeyouluo.spring.timer</groupId> 4 <artifactId>spring-timer-demo</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 7 <properties> 8 <spring.version>4.2.6.RELEASE</spring.version> 9 <slf4j.version>1.7.2</slf4j.version> 10 <log4j.version>1.2.17</log4j.version> 11 </properties> 12 13 <dependencies> 14 <dependency> 15 <groupId>org.slf4j</groupId> 16 <artifactId>slf4j-api</artifactId> 17 <version>${slf4j.version}</version> 18 </dependency> 19 <dependency> 20 <groupId>org.slf4j</groupId> 21 <artifactId>slf4j-log4j12</artifactId> 22 <version>${slf4j.version}</version> 23 </dependency> 24 <!-- common-logging 实际调用slf4j --> 25 <dependency> 26 <groupId>org.slf4j</groupId> 27 <artifactId>jcl-over-slf4j</artifactId> 28 <version>${slf4j.version}</version> 29 </dependency> 30 <!-- java.util.logging 实际调用slf4j --> 31 <dependency> 32 <groupId>org.slf4j</groupId> 33 <artifactId>jul-to-slf4j</artifactId> 34 <version>${slf4j.version}</version> 35 </dependency> 36 <dependency> 37 <groupId>log4j</groupId> 38 <artifactId>log4j</artifactId> 39 <version>${log4j.version}</version> 40 </dependency> 41 <dependency> 42 <groupId>org.lazyluke</groupId> 43 <artifactId>log4jdbc-remix</artifactId> 44 <version>0.2.7</version> 45 </dependency> 46 <!-- spring核心包 --> 47 <dependency> 48 <groupId>org.springframework</groupId> 49 <artifactId>spring-core</artifactId> 50 <version>${spring.version}</version> 51 </dependency> 52 <dependency> 53 <groupId>org.springframework</groupId> 54 <artifactId>spring-web</artifactId> 55 <version>${spring.version}</version> 56 </dependency> 57 <dependency> 58 <groupId>org.springframework</groupId> 59 <artifactId>spring-tx</artifactId> 60 <version>${spring.version}</version> 61 </dependency> 62 <dependency> 63 <groupId>org.springframework</groupId> 64 <artifactId>spring-jdbc</artifactId> 65 <version>${spring.version}</version> 66 </dependency> 67 <dependency> 68 <groupId>org.springframework</groupId> 69 <artifactId>spring-webmvc</artifactId> 70 <version>${spring.version}</version> 71 </dependency> 72 <dependency> 73 <groupId>org.springframework</groupId> 74 <artifactId>spring-aop</artifactId> 75 <version>${spring.version}</version> 76 </dependency> 77 <dependency> 78 <groupId>org.springframework</groupId> 79 <artifactId>spring-beans</artifactId> 80 <version>${spring.version}</version> 81 </dependency> 82 <dependency> 83 <groupId>org.springframework</groupId> 84 <artifactId>spring-context</artifactId> 85 <version>${spring.version}</version> 86 </dependency> 87 <dependency> 88 <groupId>org.springframework</groupId> 89 <artifactId>spring-context-support</artifactId> 90 <version>${spring.version}</version> 91 </dependency> 92 <dependency> 93 <groupId>org.springframework</groupId> 94 <artifactId>spring-expression</artifactId> 95 <version>${spring.version}</version> 96 </dependency> 97 <dependency> 98 <groupId>org.springframework</groupId> 99 <artifactId>spring-messaging</artifactId> 100 <version>${spring.version}</version> 101 </dependency> 102 <dependency> 103 <groupId>org.springframework.integration</groupId> 104 <artifactId>spring-integration-core</artifactId> 105 <version>4.2.5.RELEASE</version> 106 </dependency> 107 108 </dependencies> 109 110 <packaging>jar</packaging> 111 </project>
pom文件中可能加入了很多没有使用的jar,比如和mybatis、druid、mysql-connector相关的jar,以备后用。
①log4j.properties
1 log4j.rootLogger=INFO, Console, RollingFile 2 #Console 3 log4j.appender.Console=org.apache.log4j.ConsoleAppender 4 log4j.appender.Console.layout=org.apache.log4j.PatternLayout 5 log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n 6 7 #RollingFile 8 log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender 9 10 log4j.appender.RollingFile.File=logs/log.log 11 log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout 12 log4j.appender.RollingFile.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
②spring-base.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:task="http://www.springframework.org/schema/task" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 9 10 <bean id="readDBTask" class="com.yeyouluo.spring.timer.service.ReadDBTask"></bean> 11 12 <task:scheduled-tasks> 13 <task:scheduled ref="readDBTask" method="doSomething" cron="0/3 * * * * ?"/> 14 </task:scheduled-tasks> 15 16 </beans>
注意引入命名空间
xmlns:task=”http://www.springframework.org/schema/task“ 和
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
1 package com.yeyouluo.spring.timer.service; 2 import org.apache.log4j.Logger; 3 public class ReadDBTask { 4 public static Logger log = Logger.getLogger(ReadDBTask.class); 5 public void doSomething() { 6 log.info("********"); 7 log.info("定时任务执行。"); 8 } 9 }
1 package com.yeyouluo.spring.timer.start; 2 import org.slf4j.Logger; 3 import org.slf4j.LoggerFactory; 4 import org.springframework.context.support.ClassPathXmlApplicationContext; 5 public class Main { 6 7 public static Logger logger = LoggerFactory.getLogger(Main.class); 8 public static final String config = "spring-base.xml"; 9 10 public static void main(String[] args) { 11 12 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(config); 13 logger.info("spring timer started"); 14 if( ctx != null ) { 15 ctx.start(); 16 } 17 } 18 }
3 流程分析
在启动函数Main.java右键 –> run as –> Java Application。
结果为:每3秒在控制台输出如下:
2017-10-16 15:03:54,885 [main] INFO [com.yeyouluo.spring.timer.start.Main] - spring timer started
2017-10-16 15:03:57,002 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - **
2017-10-16 15:03:57,003 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - 定时任务执行。
2017-10-16 15:04:00,001 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - **
2017-10-16 15:04:00,001 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - 定时任务执行。
2017-10-16 15:04:03,001 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - **
2017-10-16 15:04:03,001 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - 定时任务执行。
2017-10-16 15:04:06,002 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - **
2017-10-16 15:04:06,002 [pool-1-thread-1] INFO [com.yeyouluo.spring.timer.service.ReadDBTask] - 定时任务执行。
目标:用java命令拉起程序。
步骤:
①将依赖jar提取出来,放入D:\timer\lib
②maven打包程序,将生成的jar放入D:\timer\lib
③在D:\timer\lib下新建一个文件start.cmd,内容如下:java -Djava.ext.dirs=D:\timer\lib -Xms1024m -Xmx1024m com.yeyouluo.spring.timer.start.Main
④双击start.cmd。
结果:
部署在Linux上是一样的操作,仅仅是替换启动文件类型为.sh,并且内容中的路径改为Linux的路径。
如果是部署在Linux服务器上,还可以编写如下文件:
stop.shjps | grep Main | awk ‘{print $1}‘ | xargs kill -9
注:通过kill进程的方式实现,不优雅。尤其要注意还没有其他名称为Main的进程,防止误杀。clean-log.sh
rm -f logs/*
标签:文件中 maven3 很多 exp http xms span artifact 文件类型
原文地址:http://www.cnblogs.com/helloIT/p/7683681.html