0%

maven构建的项目中默认的java版本是1.5,并且我们在项目属性里面更改了之后,

在maven-update project后又会变成默认的1.5版本,甚为烦恼。

下面提供解决方法:

Read more »

找到我们自己设置的maven的本地仓库的settings.xml文件,在镜像标签中更改默认下载依赖的路径,如用阿里云的镜像仓库地址,当然也可以选用其他的地址。

1
2
3
4
5
6
<mirror>  
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>

maven打jar包时,很容易漏掉依赖,因此需要将所有的依赖集中起来,在pom文件中做如下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.test.main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compile.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

maven项目管理中,分环境(开发、测试、生产)打包是在所难免的事情,只需要在pom文件中做一些配置。

首先是配置profiles(此处设置develop为默认环境):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!-- project environment -->
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>develop</id>
<properties>
<package.environment>develop</package.environment>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<package.environment>product</package.environment>
</properties>
</profile>
</profiles>
Read more »

ufw

ufw(Uncomplicated Firewall)是ubuntu默认的防火墙配置工具,其屏蔽了iptables的复杂操作方式,提供了非常友好的方式去配置规则。 一般情况下都会是默认安装的,若没有安装则可以输入如下命令进行安装:

1
apt install ufw
Read more »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.tradingplatform.dto;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
* 用于操作时间运算的类
* @author cc
*
*/
public class DateOperationDto {
/**
* 得到几天前的时间
* @param d
* @param day
* @return
*/
public Date getDateBefore(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
return now.getTime();
}

/**
* 得到几天后的时间
* @param d
* @param day
* @return
*/
public Date getDateAfter(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
return now.getTime();
}
public static void main(String[] args) throws ParseException {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=new Date();
System.out.println(sdf.format(date));
Date addDate=new Date(date.getTime()+600000);
System.out.println(sdf.format(addDate));
//2017-05-07 10:32:33
String oldTime="2017-05-07 10:35:34";
Date oldDate=sdf.parse(oldTime);
System.out.println(sdf.format(oldDate));
Date newTime=new Date(oldDate.getTime()+600000);
Date newTime1=new Date(oldDate.getTime()-10000);
System.out.println(newTime);
System.out.println(sdf.format(newTime));
System.out.println(sdf.format(newTime1));

}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.tradingplatform.dto;

import java.util.List;

/**
* 分页原理页面传送数据的Dto
* @param <T>:传送的数据的类型
*/
public class PageJumpDataDto<T> {
private int currentPage=1; //当前页
private int totalPage=0; //总共页
private int totalRecord=0; //总记录数
private List<T> listData; //数据
private int pageSize=6; //每页记录数

public PageJumpDataDto() {}

public PageJumpDataDto(int currentPage, int totalPage, int totalRecord, List<T> listData, int pageSize) {
super();
this.currentPage = currentPage;
this.totalPage = totalPage;
this.totalRecord = totalRecord;
this.listData = listData;
this.pageSize = pageSize;
}

public PageJumpDataDto(int currentPage, List<T> listData) {
if(listData==null) return;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}

public PageJumpDataDto(int currentPage, List<T> listData,int pageSize) {
if(listData==null) return;
this.pageSize=pageSize;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}

public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}

public List<T> getListData() {
return listData;
}

public void setListData(List<T> listData) {
this.listData = listData;
}

public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

}

下述转换属于字符串流,需要附带头文件

1
#include<<sstream>

int 转string

1
2
3
4
5
int number=100;
string str;
stringstream buffer;
buffer<<number;
buffer>>str;</span>

string转int

1
2
3
4
5
int number;
string str="666"
stringstream buffer;
buffer<<str;
buffer>>number;</span>