当前位置: 首页 > wzjs >正文

手机上怎么上传网站百度小说风云榜总榜

手机上怎么上传网站,百度小说风云榜总榜,wordpress支持建多个站点吗,wap端是指手机端吗1.问题发现 项目中有个common包资源文件,然后springboot项目引用了common,那么我们要怎么读取这个资源了。这里需要考虑三个场景,idea运行时、common jar独立运行时、springboot引用common后运行时。 2.问题解决 2.1.idea运行时 Protection…

1.问题发现

       项目中有个common包资源文件,然后springboot项目引用了common,那么我们要怎么读取这个资源了。这里需要考虑三个场景,idea运行时、common jar独立运行时、springboot引用common后运行时。

2.问题解决

2.1.idea运行时

 ProtectionDomain protectionDomain = LibPaths.class.getProtectionDomain();CodeSource codeSource = protectionDomain.getCodeSource();if (codeSource != null) {String jarPath = codeSource.getLocation().getPath();jarPath = jarPath.replaceFirst("^nested:", "");if(!jarPath.endsWith(".jar")){System.out.println("idea运行时classes路径");}

2.2.common jar运行时 

public static String getUrl(){ProtectionDomain protectionDomain = LibPaths.class.getProtectionDomain();CodeSource codeSource = protectionDomain.getCodeSource();if (codeSource != null) {String jarPath = codeSource.getLocation().getPath();jarPath = jarPath.replaceFirst("^nested:", "");System.out.println("JAR 文件路径: " + jarPath);if(jarPath != null){int index = jarPath.indexOf(".jar");String destDir = jarPath;if(index != -1){destDir = new File(jarPath.substring(0, index+4)).getParent();}if(jarPath.endsWith(".jar")){copyJarCuToOut(jarPath,destDir)}else{System.out.println("idea运行时classes路径");}}
}public static void copyJarCuToOut(String jarPath,String destDir) throws IOException {File file = new File(destDir + File.separator + "test");if(!file.exists()){file.mkdirs();copyResourcesFromJar(jarPath,destDir, true);}else{System.out.println(file.getPath() + "已存在");}
}/*** 将 JAR 中指定路径下的所有文件复制到目标目录** @param jarFilePath   JAR 文件的路径* @param resourcePath  JAR 中的资源路径(例如 "resources/")* @param destDir       目标输出目录* @throws IOException  如果复制过程中出现错误*/
public static void copyResourcesFromJar(String jarFilePath, String resourcePath, String destDir) throws IOException {try (JarFile jarFile = new JarFile(jarFilePath)) {Enumeration<JarEntry> entries = jarFile.entries();while (entries.hasMoreElements()) {JarEntry entry = entries.nextElement();if (entry.getName().startsWith(resourcePath) && !entry.isDirectory() && ( entry.getName().endsWith(".cu") || entry.getName().endsWith(".cu.h"))) {// 构建目标路径Path destPath = Paths.get(destDir + File.separator + entry.getName().substring(resourcePath.length()));// 复制文件try (InputStream is = jarFile.getInputStream(entry);OutputStream os = Files.newOutputStream(destPath)) {byte[] buffer = new byte[1024];int len;while ((len = is.read(buffer)) > 0) {os.write(buffer, 0, len);}}System.out.println("已复制: " + entry.getName() + " 到 " + destPath);}}}
}

2.3.springboot jar运行时  

public static String getUrl(){ProtectionDomain protectionDomain = LibPaths.class.getProtectionDomain();CodeSource codeSource = protectionDomain.getCodeSource();if (codeSource != null) {String jarPath = codeSource.getLocation().getPath();jarPath = jarPath.replaceFirst("^nested:", "");System.out.println("JAR 文件路径: " + jarPath);if(jarPath != null){int index = jarPath.indexOf(".jar");String destDir = jarPath;if(index != -1){destDir = new File(jarPath.substring(0, index+4)).getParent();}if(jarPath.endsWith(".jar")){copyJarCuToOut(jarPath,destDir)}else{System.out.println("idea运行时classes路径");}}
}public static void copyJarCuToOut(String jarPath,String destDir) throws IOException {File file = new File(destDir + File.separator + "test");if(!file.exists()){file.mkdirs();copyResourcesFromMultipleJar(jarPath,destDir, true);}else{System.out.println(file.getPath() + "已存在");}
}/*** 将 JAR 中指定路径下的所有文件复制到目标目录** @param jarFilePath   JAR 文件的路径* @param resourcePath  JAR 中的资源路径(例如 "resources/")* @param destDir       目标输出目录* @throws IOException  如果复制过程中出现错误*/
public static void copyResourcesFromMultipleJar(String jarFilePath, String resourcePath, String destDir) throws IOException {// 1. 分离路径部分String[] parts = jarFilePath.split("/!");if (parts.length < 2) {throw new IllegalArgumentException("无效的嵌套 JAR 路径格式");}// 2. 解析外层 JAR 路径(去掉开头的 / 和 !/)String outerJarPath = parts[0];String innerJarEntry = parts[1].replace("!/", "");System.out.println("###################" + outerJarPath);// 3. 打开外层 JARtry (JarFile outerJar = new JarFile(outerJarPath)) {// 4. 获取内层 JAR 的 EntryJarEntry innerEntry = outerJar.getJarEntry(innerJarEntry);if (innerEntry == null) {throw new FileNotFoundException("内层 JAR 不存在: " + innerJarEntry);}System.out.println("innerJarEntry###################" + innerJarEntry);try (InputStream innerIs = outerJar.getInputStream(innerEntry); JarInputStream innerJar = new JarInputStream(innerIs)) {JarEntry entry;while ((entry = innerJar.getNextJarEntry()) != null) {if (entry.getName().startsWith(resourcePath) && !entry.isDirectory()) {// 构建目标路径Path destPath = Paths.get(destDir + File.separator + entry.getName().substring(resourcePath.length()));// 复制文件try (OutputStream os = Files.newOutputStream(destPath)) {byte[] buffer = new byte[1024];int len;while ((len = innerJar.read(buffer)) > 0) {os.write(buffer, 0, len);}}System.out.println("已复制: " + entry.getName() + " 到 " + destPath);}}}}}

2.4.完整代码

package com.omega.common.lib;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;public class LibPaths {static {try {// 获取 ProtectionDomain 和 CodeSourceProtectionDomain protectionDomain = LibPaths.class.getProtectionDomain();CodeSource codeSource = protectionDomain.getCodeSource();if (codeSource != null) {String jarPath = codeSource.getLocation().getPath();jarPath = jarPath.replaceFirst("^nested:", "");System.out.println("JAR 文件路径: " + jarPath);if(jarPath != null){int index = jarPath.indexOf(".jar");String destDir = jarPath;if(index != -1){destDir = new File(jarPath.substring(0, index+4)).getParent();}if(jarPath.endsWith(".jar")){copyJarCuToOut(jarPath,destDir, false);}else if(jarPath.endsWith(".jar!/")){copyJarCuToOut(jarPath,destDir, true);}LIB_PATH = destDir + File.separator + "test";}else{System.out.println("JAR 文件路径为空");}} else {System.out.println("无法获取 JAR 路径(可能来自系统类加载器)");}} catch (IOException e) {e.printStackTrace();}}public static void copyJarCuToOut(String jarPath,String destDir, boolean multiple) throws IOException {File file = new File(destDir + File.separator + "test");if(!file.exists()){file.mkdirs();if(multiple){copyResourcesFromMultipleJar(jarPath, "test", file.getPath());}else{copyResourcesFromJar(jarPath, "test", file.getPath());}}else{System.out.println(file.getPath() + "已存在");}}/*** 将 JAR 中指定路径下的所有文件复制到目标目录** @param jarFilePath   JAR 文件的路径* @param resourcePath  JAR 中的资源路径(例如 "resources/")* @param destDir       目标输出目录* @throws IOException  如果复制过程中出现错误*/public static void copyResourcesFromJar(String jarFilePath, String resourcePath, String destDir) throws IOException {try (JarFile jarFile = new JarFile(jarFilePath)) {Enumeration<JarEntry> entries = jarFile.entries();while (entries.hasMoreElements()) {JarEntry entry = entries.nextElement();if (entry.getName().startsWith(resourcePath) && !entry.isDirectory() && ( entry.getName().endsWith(".cu") || entry.getName().endsWith(".cu.h"))) {// 构建目标路径Path destPath = Paths.get(destDir + File.separator + entry.getName().substring(resourcePath.length()));// 复制文件try (InputStream is = jarFile.getInputStream(entry);OutputStream os = Files.newOutputStream(destPath)) {byte[] buffer = new byte[1024];int len;while ((len = is.read(buffer)) > 0) {os.write(buffer, 0, len);}}System.out.println("已复制: " + entry.getName() + " 到 " + destPath);}}}}/*** 将 JAR 中指定路径下的所有文件复制到目标目录** @param jarFilePath   JAR 文件的路径* @param resourcePath  JAR 中的资源路径(例如 "resources/")* @param destDir       目标输出目录* @throws IOException  如果复制过程中出现错误*/public static void copyResourcesFromMultipleJar(String jarFilePath, String resourcePath, String destDir) throws IOException {// 1. 分离路径部分String[] parts = jarFilePath.split("/!");if (parts.length < 2) {throw new IllegalArgumentException("无效的嵌套 JAR 路径格式");}// 2. 解析外层 JAR 路径(去掉开头的 / 和 !/)String outerJarPath = parts[0];String innerJarEntry = parts[1].replace("!/", "");System.out.println("###################" + outerJarPath);// 3. 打开外层 JARtry (JarFile outerJar = new JarFile(outerJarPath)) {// 4. 获取内层 JAR 的 EntryJarEntry innerEntry = outerJar.getJarEntry(innerJarEntry);if (innerEntry == null) {throw new FileNotFoundException("内层 JAR 不存在: " + innerJarEntry);}System.out.println("innerJarEntry###################" + innerJarEntry);try (InputStream innerIs = outerJar.getInputStream(innerEntry); JarInputStream innerJar = new JarInputStream(innerIs)) {JarEntry entry;while ((entry = innerJar.getNextJarEntry()) != null) {if (entry.getName().startsWith(resourcePath) && !entry.isDirectory()) {// 构建目标路径Path destPath = Paths.get(destDir + File.separator + entry.getName().substring(resourcePath.length()));// 复制文件try (OutputStream os = Files.newOutputStream(destPath)) {byte[] buffer = new byte[1024];int len;while ((len = innerJar.read(buffer)) > 0) {os.write(buffer, 0, len);}}System.out.println("已复制: " + entry.getName() + " 到 " + destPath);}}}}}}


文章转载自:

http://JUxXkwSD.Ljmbd.cn
http://vFDiBP4d.Ljmbd.cn
http://2p5F7ijS.Ljmbd.cn
http://bi71p1N4.Ljmbd.cn
http://O3J8tpLN.Ljmbd.cn
http://rJw2ArmA.Ljmbd.cn
http://neWiAiWw.Ljmbd.cn
http://SnnYRuyg.Ljmbd.cn
http://9BGc8dvJ.Ljmbd.cn
http://EjVejWc3.Ljmbd.cn
http://pD5EVeHz.Ljmbd.cn
http://OgnZMlsn.Ljmbd.cn
http://NqkSvzoj.Ljmbd.cn
http://ormgAWmD.Ljmbd.cn
http://YbCh72xZ.Ljmbd.cn
http://ioedRjI0.Ljmbd.cn
http://3oqTJGKw.Ljmbd.cn
http://aIjEeJqz.Ljmbd.cn
http://NfwU6iNc.Ljmbd.cn
http://bRCL6w7t.Ljmbd.cn
http://HSs3Kuu2.Ljmbd.cn
http://uW8mS3ab.Ljmbd.cn
http://z96lei6r.Ljmbd.cn
http://64MQvPRN.Ljmbd.cn
http://S17kqSlL.Ljmbd.cn
http://3CInEi7k.Ljmbd.cn
http://zngTNjon.Ljmbd.cn
http://A7OVfrjt.Ljmbd.cn
http://7NT9E6KT.Ljmbd.cn
http://GcNQl8WI.Ljmbd.cn
http://www.dtcms.com/wzjs/644730.html

相关文章:

  • php网站后台密码破解程序微信商城系统哪找
  • 南京品牌网站设计拿p5.js做的网站
  • 建设彩票网站制作吴江区经济开发区建设工程网站
  • 团购网站推广怎么做华为手机应用引擎
  • 自己做网站开店免费建站系统博客
  • 注册安全工程师建设工程网站平面作品集展示图片
  • 曲阜网站建设价格wordpress怎么启用经典编辑器
  • 濮阳建设网站做图剪片文案网站app接单
  • 如何建立网站的步骤北京顺义去哪找做网站的
  • 整站下载器 做网站地图网站建设与分工的论文
  • 青岛网站制作公司上海网站建设-网建知识
  • 管理系统官方网站wordpress菜单高度
  • 网站应用软件设计物流门户网站源码
  • 博客建站系统建设网站设备预算
  • 北京网站营销与推广qq群推广方法
  • 甘肃省安装建设集团公司网站医药网站前置审批
  • 网站域名空间代理丹徒网站建设怎么样
  • 重庆那里做网站外包好docker搭建wordpress
  • 成都企业网站建设公司电话东莞自己注册公司流程
  • 垂直网站建设的关键因素网站维护都要做什么
  • idc 网站备案某旅行社网站建设策划书
  • 石狮网站医院咨询男科
  • 安全的网站建设公哈尔滨h5制作
  • 中国做的电脑系统下载网站好天元建设集团有限公司商业承兑汇票
  • 注册网站域名要钱吗遵义门户网站
  • 网站开发的背景网站建设佰首选金手指二七
  • 公司网站建设代理一般做多久网站建设不要摸板
  • 建设网站企业哪家好做实体上什么网站找项目
  • 2018企业网站优化应该怎么做市政建设招标网站有哪些
  • 模板下载网站什么好网站制作哈尔滨