Skip to content

Commit e8583c6

Browse files
committed
fix 2.0.4
1 parent 613dee9 commit e8583c6

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

springboot-starter/src/main/java/com/codingapi/springboot/framework/boot/DynamicApplication.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import org.springframework.boot.SpringApplication;
55
import org.springframework.context.ConfigurableApplicationContext;
66

7-
import java.io.IOException;
87
import java.net.URL;
98
import java.net.URLClassLoader;
109
import java.nio.file.Files;
1110
import java.nio.file.Path;
1211
import java.nio.file.Paths;
1312
import java.util.ArrayList;
1413
import java.util.List;
14+
import java.util.stream.Stream;
1515

1616
public class DynamicApplication {
1717

@@ -40,6 +40,7 @@ public void run0(Class<?> applicationClass, String[] args) {
4040

4141

4242
public static void run(Class<?> applicationClass, String[] args) {
43+
DynamicApplication.getInstance().addDynamicJars();
4344
DynamicApplication.getInstance().run0(applicationClass, args);
4445
}
4546

@@ -50,31 +51,29 @@ public static void restart() {
5051
public void restart0() {
5152
Thread thread = new Thread(() -> {
5253
context.close();
53-
try {
54-
this.addDynamicJars();
55-
} catch (IOException e) {
56-
throw new RuntimeException(e);
57-
}
54+
this.addDynamicJars();
5855
this.run0(applicationClass, runArgs);
5956
});
6057
thread.setDaemon(false);
6158
thread.start();
6259
}
6360

64-
private void addDynamicJars() throws IOException {
61+
private void addDynamicJars(){
6562
Path libsPath = Paths.get(jarsFolder);
6663
if (Files.exists(libsPath) && Files.isDirectory(libsPath)) {
6764
System.out.println("Start Load Dynamic Jars:");
6865
List<URL> jarUrls = new ArrayList<>();
69-
Files.list(libsPath)
70-
.filter(file -> file.toString().endsWith(".jar"))
71-
.forEach(file -> {
72-
try {
73-
URL url = file.toUri().toURL();
74-
jarUrls.add(url);
75-
System.out.println(url);
76-
} catch (Exception ignored) {}
77-
});
66+
try(Stream<Path> stream = Files.list(libsPath)){
67+
stream
68+
.filter(file -> file.toString().endsWith(".jar"))
69+
.map(Path::toUri)
70+
.forEach(uri -> {
71+
try {
72+
jarUrls.add(uri.toURL());
73+
System.out.println(uri);
74+
} catch (Exception ignored) {}
75+
});
76+
}catch (Exception ignored){}
7877
URL[] urls = jarUrls.toArray(new URL[0]);
7978
URLClassLoader urlClassLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
8079
Thread.currentThread().setContextClassLoader(urlClassLoader);

0 commit comments

Comments
 (0)