LittleBill

Intellij IDEA为Maven私有仓库与Resin搭建集成开发环境

开头先用图示的方式介绍一下Maven中央仓库、私有服务器、与本地仓库的关系,如下图:

上面非常直观的解释他们这三者之间的关系,本人就不再详细展开说明,不明白的请自行Google :)

下面直接进入主题,因为项目需要使用Maven中央仓库与私有仓库的jar包并要运行Resin中,同时采用直接部署代码的方式而非用war包的方式部署项目。

下面我详细是一下配置方法:
按照惯例,先介绍一下开发环境版本:
OS:windows 7
IDE:Intellij IDEA 2016.3.4;
Build Automation:Apache Maven 3.2.5;
Server:Resin-3.1.14;
我这里不介绍如何安装Intellij IDEA、Maven、Resin,不会的请自行Google;

(1)配置Maven私有仓库,让Intellij IDEA(以下简称idea)根据Maven全局配置文件自动识别私有仓库地址,并自动下载项目中依赖的jar包;

[xml]
<profiles>
<profile>
<!– profile的唯一标识 –>
<id>Test</id>
<!– 远程仓库列表 –>
<repositories>
<!–包含需要连接到远程仓库的信息 –>
<repository>
!–远程仓库唯一标识 –>
<id>Test</id>
<!–远程仓库名称 –>
<name>Test-Repository</name>
<url>http://url…</url>
<!–如何处理远程仓库里发布版本的下载 –>
<releases>
<!–true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 –>
<enabled>true</enabled>
</releases>
<!–如何处理远程仓库里快照版本的下载。–>
<snapshots
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>

<!– 手动激活profiles的列表 –>
<activeProfiles>
<activeProfile>Test</activeProfile>
</activeProfiles>
[/xml]
[……]

继续阅读

Continue reading

用Java生成随机密码的方法

最近各种数据库泄露问题,让我不得不考虑自身密码的强度,下面特意写两种生成密码的方法,已被日后之用;

介绍两种生成随机密码的方式:(在密码字典里面,可以根据实际需要,手工注释不需要生成的字符段)

方式一:
[java]
/**
* 生成随机密码生成方式一
* 密码字典 -> 随机获取字符
* @param len 生成密码长度
* @return
*/
public static String getPassWordOne(int len){
int i; //生成的随机数
int count = 0; //生成的密码的长度
// 密码字典
char[] str = {
‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’,
‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’,
‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’,
‘~’, ‘!’, ‘@’, ‘#’, ‘$’, ‘%’, ‘^’, ‘-‘, ‘+’
};
StringBuffer stringBuffer = new StringBuffer("");
Random r = new Random();
while(count < len){
//生成 0 ~ 密码字典-1之间的随机数
i = r.nextInt(str.length);
stringBuffer.append(str[i]);
count ++;
}
return stringBuffer.toString();
}
[/java]

方式二:
[……]

继续阅读

Continue reading

使用jsoup对HTML文档进行解析简要介绍

这里只介绍如何使用jsoup的方法,其它代码略过。
首先下载jsoup
其次,看看下面示例代码;
[java]
/**
* 获取<script>标签中src地址或者获取<a>标签中href地址
* String html 获取页面源代码
* String rule 选择器规则
*/
Set<String> links = new LinkedHashSet<String>();
… …
Document doc = Jsoup.parse(html);
Elements clicks = doc.select(rule);
if (clicks.size() == 1) {
if (rule.indexOf("src") > 0) {
links.add(clicks.get(0).attr("src"));
}
} else {
for(Element et : clicks){
links.add(et.attr("href"));
}
}
… …
[/java]
[……]

继续阅读

Continue reading