
com.njzxw.compress_maven_plugin.util.CopyDirectory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compress-maven-plugin Show documentation
Show all versions of compress-maven-plugin Show documentation
配置监控信息,在web.xml中添加
<filter>
<description>拦截获取js与css过滤</description>
<filter-name>MergeFilter</filter-name>
<filter-class>com.njzxw.filter.MergeFilter</filter-class>
<init-param>
<!-- js合并输出路径 -->
<param-name>jsDir</param-name>
<param-value>${js.path}</param-value>
</init-param>
<init-param>
<!-- css合并输出路径 -->
<param-name>cssDir</param-name>
<param-value>${css.path}</param-value>
</init-param>
</filter>
同时添加一个合并js\css对应一个merge.xml,最好放置在同级,如:
<merge>
<group name="sss" >
<js path="js/common/common.js" />
<js path="js/common/index.js" />
<css path="css/common/animate.css" />
<css path="css/common/normalize.css" />
</group>
</merge>
访问项目:xxx/sss.js
xxx/sss.css
同时配合maven插件: compress-maven-plugin结合使用:
<plugin>
<groupId>com.github.eliayng</groupId>
<artifactId>compress-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>${skipCompress}</skip>
<poolNum>50</poolNum>
<jsOutDir>${jsOutDir}</jsOutDir>
<cssOutDir>${cssOutDir}</cssOutDir>
<!--是否监控编译class文件-->
<isCompressClass>true</isCompressClass>
<!-- 是否复制资源文件 -->
<isResourcesCopy>true</isResourcesCopy>
</configuration>
</plugin>
The newest version!
package com.njzxw.compress_maven_plugin.util;
import java.io.*;
/**
* 复制文件夹或文件夹
*/
public class CopyDirectory {
// 源文件夹
String url1 = "E:\\workspace\\DeployeTest";
// 目标文件夹
String url2 = "E:\\java\\project\\bin";
public static void main(String args[]) throws IOException {
CopyDirectory copyDirectory = new CopyDirectory();
// 创建目标文件夹
(new File(copyDirectory.url2)).mkdirs();
// 获取源文件夹当前下的文件或目录
File[] file = (new File(copyDirectory.url1)).listFiles();
for (int i = 0; i < file.length; i++) {
if (file[i].isFile()) {
// 复制文件
copyDirectory.copyFile(file[i], new File(copyDirectory.url2 + file[i].getName()));
}
if (file[i].isDirectory()) {
// 复制目录
String sourceDir = copyDirectory.url1 + File.separator + file[i].getName();
String targetDir = copyDirectory.url2 + File.separator + file[i].getName();
copyDirectory.copyDirectiory(sourceDir, targetDir);
}
}
}
/**
* 复制文件
*
* @param sourceFile 源文件
* @param targetFile 目标文件
* @throws IOException
*/
public void copyFile(File sourceFile, File targetFile)
throws IOException {
// 新建文件输入流并对它进行缓冲
FileInputStream input = new FileInputStream(sourceFile);
BufferedInputStream inBuff = new BufferedInputStream(input);
// 新建文件输出流并对它进行缓冲
FileOutputStream output = new FileOutputStream(targetFile);
BufferedOutputStream outBuff = new BufferedOutputStream(output);
// 缓冲数组
byte[] b = new byte[1024 * 5];
int len;
while ((len = inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
// 刷新此缓冲的输出流
outBuff.flush();
// 关闭流
inBuff.close();
outBuff.close();
output.close();
input.close();
}
/**
* 复制文件夹
*
* @param sourceDir 源文件夹路径
* @param targetDir 目标文件夹路径
* @throws IOException
*/
public void copyDirectiory(String sourceDir, String targetDir)
throws IOException {
// 新建目标目录
(new File(targetDir)).mkdirs();
// 获取源文件夹当前下的文件或目录
File[] file = (new File(sourceDir)).listFiles();
for (int i = 0; i < file.length; i++) {
if (file[i].isFile()) {
// 源文件
File sourceFile = file[i];
// 目标文件
File targetFile = new File(new File(targetDir)
.getAbsolutePath()
+ File.separator + file[i].getName());
copyFile(sourceFile, targetFile);
}
if (file[i].isDirectory()) {
// 准备复制的源文件夹
String dir1 = sourceDir + "/" + file[i].getName();
// 准备复制的目标文件夹
String dir2 = targetDir + "/" + file[i].getName();
copyDirectiory(dir1, dir2);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy