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
- [ ] Optimize performance
## ~~Maven Repository~~
## Maven Repository
```xml
<dependency>
<groupId>com.gitee.Biubiuyuyu</groupId>
<artifactId>javafx-plus</artifactId>
<version>1.0.0-RELEASE</version>
<version>1.2.1-SNAPSHOT</version>
</dependency>
```

35
pom.xml
View File

@@ -25,6 +25,7 @@
<slf4j-log4j12.version>1.7.21</slf4j-log4j12.version>
<tomcat.version>9.0.48</tomcat.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-io.version>2.11.0</commons-io.version>
</properties>
<dependencies>
<!-- 第三方动态代理库 -->
@@ -60,6 +61,12 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>
<distributionManagement>
@@ -118,6 +125,20 @@
</descriptorRefs>
</configuration>
</plugin>
<!-- Source 开源 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@@ -126,20 +147,6 @@
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<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.log.FXPlusLoggerFactory;
import cn.edu.scau.biubiusuisui.log.IFXPlusLogger;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import java.io.*;
import java.net.URL;
@@ -34,12 +35,28 @@ public class FileUtil {
* @param filePath
* @return
* @description 读取resources文件夹下的file相对于resources的文件路径如 resources/config.conf 则只需 config.conf
* @since 1.2.0 update: 使用getResourcesAsStream读取屏蔽jar包读取障碍
*/
public static String readFileFromResources(String filePath) throws UnsupportedEncodingException {
URL url = FileUtil.class.getClassLoader().getResource(filePath);
if (url != null) {
String path = StringUtil.getRootPath(url);
return readFile(path);
InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(filePath);
if (is == null) {
return "";
}
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 "";
}
@@ -60,8 +77,7 @@ public class FileUtil {
content.append(temp + "\r\n");
}
} catch (IOException e) {
logger.error(e.getMessage());
e.printStackTrace();
logger.error("reading file error", e);
}
return content.toString();
}