Maven pom.xml文件获取当前时间戳方式
maven pom.xml文件获取当前时间戳
今天发布项目到测试环境,发布完成后,一直启动不起来,查看日志发现java.lang.outofmemoryerror: java heap space.
java.lang.outofmemoryerror: java heap space
dumping heap to /dump/dump.hprof
unable to create /dump/dump.hprof: file exists
原maven pom.xml配置如下
-xx:metaspacesize=128m -xx:maxmetaspacesize=512m -xx:+heapdumponoutofmemoryerror -xx:heapdumppath=/dump/dump.hprof
问题
所以每次系统出现outofmemoryerror时,系统自动会dump内存快照到/dump/dump.hprof文件里. 如果第一次dump完成后,第二次就会提示file exists
解决方案
在dump.hprof文件后面添加时间戳
新maven pom.xml配置如下
<properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <!-- 设置时间格式 --> <maven.build.timestamp.format>yyyymmddhhmmss</maven.build.timestamp.format> </properties> -xx:+heapdumponoutofmemoryerror -xx:heapdumppath=/dump/dump${maven.build.timestamp}.hprof
如果再出现outofmemoryerror错误, dump下来的文件 /dump/dump20181206112111.hprof
maven打包加时间戳方法总结
基于maven的项目,发布时需要打包,如tar.gz。web项目打成war格式包。每次打包时希望自己加上时间戳,假如我的项目名是myproject,默认打包后名为myproject.war。而我希望的名字为myproject-1.0.0-20160217。方便以后对包进行查找与管理,如何实现这种效果呢?
1.使用maven自带的属性
设置时间戳格式:在pom.xml文件中加入以下配置
<properties> <maven.build.timestamp.format>yyyymmddhhmmss</maven.build.timestamp.format> </properties>
在打包plugin中引用该属性
<finalname> ${project.artifactid}-${project.version}_${maven.build.timestamp} </finalname>
maven自带时间戳使用${maven.build.timestamp},但是时区是utc。
如果要使用gmt+8,就需要插件提供支持,以下两个插件可以实现。
2.使用buildnubmer-maven-plugin
<plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>buildnumber-maven-plugin</artifactid> <version>1.4</version> <configuration> <timestampformat>yyyymmdd</timestampformat> </configuration> <executions> <execution> <goals> <goal>create-timestamp</goal> </goals> </execution> </executions> <inherited>false</inherited> </plugin>
默认属性是timestamp,在打包plugin中引用该属性
<finalname> ${project.artifactid}-${project.version}_${timestamp} </finalname>
3.使用build-helper-maven-plugin
<build> <finalname>projectname-${current.time}</finalname> <plugins> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>build-helper-maven-plugin</artifactid> <version>1.9.1</version> <executions> <execution> <id>timestamp-property</id> <goals> <goal>timestamp-property</goal> </goals> </execution> </executions> <configuration> <name>current.time</name> <pattern>yyyymmdd-hhmmss</pattern> <timezone>gmt+8</timezone> </configuration> </plugin> </plugins> </build>
将以上的几种方式配置分别加入到自己的pom.xml文件中,打个包试试,是不是自己加上了时间戳
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。