Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
commit
839505b9bb
|
@ -55,7 +55,7 @@ public class BuilderPackageEcology extends Application {
|
|||
try {
|
||||
FileCompressor.compressFiles(filePaths, outputFile.getAbsolutePath(), path -> {
|
||||
String rootPath = Util.class.getResource("/").getPath();
|
||||
rootPath = rootPath.split(File.separator + "target" + File.separator)[0] + File.separator + "target" + File.separator + "classes" + File.separator;
|
||||
rootPath = rootPath.split(File.separator + FileTreeBuilder.targetPath)[0] + File.separator + FileTreeBuilder.targetPath + "classes" + File.separator;
|
||||
String replace = "/ecology/" + (isEcology ? "WEB-INF/classes/" : "classbean/");
|
||||
if (path.endsWith(".jar")) {
|
||||
replace = "/ecology/WEB-INF/lib/";
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package builderpackage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
/**
|
||||
* <h1>测试自动打包</h1>
|
||||
*
|
||||
* <p>create: 2023/7/4 16:34</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
public class AutoPackageJar {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String path = AutoPackageJar.class.getResource("").getPath();
|
||||
String finalPath = path.split("/target/")[0] + File.separator + "target/classes" + File.separator;
|
||||
System.out.println(finalPath);
|
||||
createJar(finalPath + "aiyh", finalPath + "aiyh_utils.jar");
|
||||
}
|
||||
|
||||
public static void createJar(String targetPath) {
|
||||
String path = AutoPackageJar.class.getResource("").getPath();
|
||||
String finalPath = path.split(File.separator + targetPath)[0] + File.separator + targetPath + File.separator + "classes" + File.separator;
|
||||
createJar(finalPath + "aiyh", finalPath + "aiyh_utils.jar");
|
||||
createJar(finalPath + "ebu7common", finalPath + "ebu7common.jar");
|
||||
}
|
||||
|
||||
public static void createJar(String folderName, String jarName) {
|
||||
File folder = new File(folderName);
|
||||
File jarFile = new File(jarName);
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(jarFile);
|
||||
JarOutputStream jos = new JarOutputStream(fos)) {
|
||||
|
||||
addFolderToJar("", folder, jos);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void addFolderToJar(String parentPath, File folder, JarOutputStream jos) throws IOException {
|
||||
String entryName = parentPath + folder.getName() + "/";
|
||||
jos.putNextEntry(new JarEntry(entryName));
|
||||
jos.closeEntry();
|
||||
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
addFolderToJar(entryName, file, jos);
|
||||
} else {
|
||||
addFileToJar(entryName, file, jos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addFileToJar(String entryPath, File file, JarOutputStream jos) throws IOException {
|
||||
String entryName = entryPath + file.getName();
|
||||
jos.putNextEntry(new JarEntry(entryName));
|
||||
|
||||
// 读取文件内容并写入到jar包中
|
||||
// 这里假设你的文件不是太大,可以一次性读取到内存中
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
jos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
jos.closeEntry();
|
||||
}
|
||||
}
|
|
@ -12,18 +12,12 @@ public class FileTreeBuilder {
|
|||
public static final String DIRECTORY_TYPE = "文件夹";
|
||||
public static final String FILE_TYPE = "文件";
|
||||
|
||||
public static String targetPath;
|
||||
|
||||
public static FileInfo buildFileTree() {
|
||||
String directoryPath = "target/";
|
||||
String directoryPath = "target";
|
||||
List<String> blackList = new ArrayList<>();
|
||||
List<String> blacklistPrefixes = Arrays.asList(
|
||||
"target" + File.separator + "generated-sources",
|
||||
"target" + File.separator + "generated-test-sources",
|
||||
"target" + File.separator + "test-classes",
|
||||
"target" + File.separator + "classes" + File.separator + "aiyh",
|
||||
"target" + File.separator + "classes" + File.separator + "ebu7common",
|
||||
"target" + File.separator + "classes" + File.separator + "ln",
|
||||
"target" + File.separator + "classes" + File.separator + "cus_getlog"
|
||||
);
|
||||
|
||||
Properties properties = new Properties();
|
||||
try (InputStream inputStream = FileTreeBuilder.class.getClassLoader().getResourceAsStream("application.properties")) {
|
||||
properties.load(inputStream);
|
||||
|
@ -33,7 +27,24 @@ public class FileTreeBuilder {
|
|||
String[] split = value.split(";");
|
||||
Collections.addAll(blackList, split);
|
||||
}
|
||||
directoryPath = properties.getProperty("packageRootPath");
|
||||
String packageRootPath = properties.getProperty("packageRootPath");
|
||||
if (StrUtil.isNotBlank(packageRootPath)) {
|
||||
directoryPath = packageRootPath;
|
||||
if (!directoryPath.endsWith(File.separator)) {
|
||||
directoryPath += File.separator;
|
||||
}
|
||||
targetPath = directoryPath;
|
||||
}
|
||||
List<String> blacklistPrefixes = Arrays.asList(
|
||||
directoryPath + "generated-sources",
|
||||
directoryPath + "generated-test-sources",
|
||||
directoryPath + "test-classes",
|
||||
directoryPath + "classes" + File.separator + "aiyh",
|
||||
directoryPath + "classes" + File.separator + "ebu7common",
|
||||
directoryPath + "classes" + File.separator + "ln",
|
||||
directoryPath + "classes" + File.separator + "cus_getlog"
|
||||
);
|
||||
AutoPackageJar.createJar(directoryPath);
|
||||
blackList.addAll(blacklistPrefixes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue