1 Commits
1.3.0 ... 1.2.1

Author SHA1 Message Date
suisui
8a7efd76c6 fix:修复打包后读取jar包资源文件异常 2021-09-16 23:43:55 +08:00
3 changed files with 45 additions and 22 deletions

View File

@@ -85,13 +85,13 @@ The framework is not the framework for beautifying UI, but to simplify the step
- [ ] Data valication - [ ] Data valication
- [ ] Optimize performance - [ ] Optimize performance
## ~~Maven Repository~~ ## Maven Repository
```xml ```xml
<dependency> <dependency>
<groupId>com.gitee.Biubiuyuyu</groupId> <groupId>com.gitee.Biubiuyuyu</groupId>
<artifactId>javafx-plus</artifactId> <artifactId>javafx-plus</artifactId>
<version>1.0.0-RELEASE</version> <version>1.2.1-SNAPSHOT</version>
</dependency> </dependency>
``` ```

27
pom.xml
View File

@@ -25,6 +25,7 @@
<slf4j-log4j12.version>1.7.21</slf4j-log4j12.version> <slf4j-log4j12.version>1.7.21</slf4j-log4j12.version>
<tomcat.version>9.0.48</tomcat.version> <tomcat.version>9.0.48</tomcat.version>
<commons-lang3.version>3.12.0</commons-lang3.version> <commons-lang3.version>3.12.0</commons-lang3.version>
<commons-io.version>2.11.0</commons-io.version>
</properties> </properties>
<dependencies> <dependencies>
<!-- 第三方动态代理库 --> <!-- 第三方动态代理库 -->
@@ -60,6 +61,12 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version> <version>${commons-lang3.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies> </dependencies>
<distributionManagement> <distributionManagement>
@@ -118,19 +125,11 @@
</descriptorRefs> </descriptorRefs>
</configuration> </configuration>
</plugin> </plugin>
</plugins> <!-- Source 开源 -->
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version> <version>3.0.1</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -140,6 +139,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Javadoc --> <!-- Javadoc -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@@ -3,6 +3,7 @@ package cn.edu.scau.biubiusuisui.utils;
import cn.edu.scau.biubiusuisui.exception.ProtocolNotSupport; import cn.edu.scau.biubiusuisui.exception.ProtocolNotSupport;
import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory; import cn.edu.scau.biubiusuisui.log.FXPlusLoggerFactory;
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger; import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
@@ -34,12 +35,28 @@ public class FileUtil {
* @param filePath * @param filePath
* @return * @return
* @description 读取resources文件夹下的file相对于resources的文件路径如 resources/config.conf 则只需 config.conf * @description 读取resources文件夹下的file相对于resources的文件路径如 resources/config.conf 则只需 config.conf
* @since 1.2.0 update: 使用getResourcesAsStream读取屏蔽jar包读取障碍
*/ */
public static String readFileFromResources(String filePath) throws UnsupportedEncodingException { public static String readFileFromResources(String filePath) throws UnsupportedEncodingException {
URL url = FileUtil.class.getClassLoader().getResource(filePath); InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(filePath);
if (url != null) { if (is == null) {
String path = StringUtil.getRootPath(url); return "";
return readFile(path); }
StringBuffer content = new StringBuffer();
try (
InputStreamReader inputStreamReader = new InputStreamReader(is);
BufferedReader br = new BufferedReader(inputStreamReader);
) {
String temp;
while ((temp = br.readLine()) != null) {
// 一次读入一行数据
content.append(temp + "\r\n");
}
return content.toString();
} catch (IOException e) {
logger.error("reading file error", e);
} finally {
IOUtils.closeQuietly(is);
} }
return ""; return "";
} }
@@ -60,8 +77,7 @@ public class FileUtil {
content.append(temp + "\r\n"); content.append(temp + "\r\n");
} }
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage()); logger.error("reading file error", e);
e.printStackTrace();
} }
return content.toString(); return content.toString();
} }