From 0bd6f83a44ec6d85f6f2aa81b99bdff32b132f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BB=BA=E5=9B=BD?= Date: Tue, 11 Feb 2025 16:12:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(show):=20=E4=BC=98=E5=8C=96=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优先从类路径资源中加载图标 - 如果类路径资源中不存在,再从外部路径加载图标 - 增加日志输出,方便调试- 更新项目版本号至 0.1.6.2 --- pom.xml | 2 +- src/main/java/org/aohe/show/IconUtil.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9ae8f8b..b4488f8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.aohe twain-service - 0.1.6.1 + 0.1.6.2 8 diff --git a/src/main/java/org/aohe/show/IconUtil.java b/src/main/java/org/aohe/show/IconUtil.java index 932d065..5b412fe 100644 --- a/src/main/java/org/aohe/show/IconUtil.java +++ b/src/main/java/org/aohe/show/IconUtil.java @@ -1,6 +1,7 @@ package org.aohe.show; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.resource.ClassPathResource; import cn.hutool.core.io.resource.ResourceUtil; import lombok.extern.slf4j.Slf4j; @@ -9,11 +10,18 @@ import java.awt.*; @Slf4j public class IconUtil { public static Image getIcon() { - String iconPath = "ah.png"; + ClassPathResource resource = new ClassPathResource("ah.png"); + if(FileUtil.exist(resource.getFile())){ + return Toolkit.getDefaultToolkit().getImage(resource.getPath()); + } + String iconPath = "..\\ah.png"; + log.info("当前查找路径为外部:{}", FileUtil.getAbsolutePath(iconPath)); if(!FileUtil.exist("ah.png")){ iconPath = ResourceUtil.getResource("ah.png").getFile(); + log.info("当前查找路径为内部:{}", FileUtil.getAbsolutePath(iconPath)); } - log.info("当前查找路径为:{}", FileUtil.getAbsolutePath(iconPath)); - return Toolkit.getDefaultToolkit().getImage(FileUtil.getAbsolutePath(iconPath)); + + + return Toolkit.getDefaultToolkit().getImage(iconPath); } }