Skip to content

Commit 1858d5f

Browse files
committed
1.修改类加载器bug
1 parent 9249c7c commit 1858d5f

3 files changed

Lines changed: 22 additions & 23 deletions

File tree

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454

5555
<!-- https://mvnrepository.com/artifact/io.github.classgraph/classgraph -->
5656
<!-- https://github.com/classgraph/classgraph -->
57-
<dependency>
58-
<groupId>io.github.classgraph</groupId>
59-
<artifactId>classgraph</artifactId>
60-
<version>4.8.100</version>
61-
</dependency>
57+
<!-- <dependency>-->
58+
<!-- <groupId>io.github.classgraph</groupId>-->
59+
<!-- <artifactId>classgraph</artifactId>-->
60+
<!-- <version>4.8.100</version>-->
61+
<!-- </dependency>-->
6262
</dependencies>
6363
<build>
6464
<plugins>

src/main/java/com/xwintop/xJavaFxTool/plugin/PluginClassLoader.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.xwintop.xJavaFxTool.plugin;
22

3-
import io.github.classgraph.ClassGraph;
4-
53
import java.io.File;
64
import java.net.MalformedURLException;
7-
import java.net.URI;
85
import java.net.URL;
96
import java.net.URLClassLoader;
10-
import java.util.ArrayList;
11-
import java.util.List;
127

138
/**
149
* 用于加载插件的 ClassLoader
@@ -20,17 +15,22 @@ public static PluginClassLoader create(File jarFile) {
2015
}
2116

2217
public static PluginClassLoader create(ClassLoader parent, File jarFile) {
23-
List<URI> uris = new ArrayList<>(new ClassGraph().getClasspathURIs());
24-
uris.add(jarFile.toURI());
25-
26-
URL[] urls = uris.stream().map(uri -> {
27-
try {
28-
return uri.toURL();
29-
} catch (MalformedURLException e) {
30-
throw new RuntimeException(e);
31-
}
32-
}).toArray(URL[]::new);
33-
18+
// List<URI> uris = new ArrayList<>(new ClassGraph().getClasspathURIs());
19+
// uris.add(jarFile.toURI());
20+
// URL[] urls = uris.stream().map(uri -> {
21+
// try {
22+
// return uri.toURL();
23+
// } catch (MalformedURLException e) {
24+
// throw new RuntimeException(e);
25+
// }
26+
// }).toArray(URL[]::new);
27+
28+
URL[] urls = null;
29+
try {
30+
urls = new URL[]{jarFile.toURI().toURL()};
31+
} catch (MalformedURLException e) {
32+
throw new RuntimeException(e);
33+
}
3434
return new PluginClassLoader(urls, parent);
3535
}
3636

src/main/java/com/xwintop/xJavaFxTool/services/IndexService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.xwintop.xJavaFxTool.common.logback.ConsoleLogAppender;
66
import com.xwintop.xJavaFxTool.controller.IndexController;
77
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
8-
import com.xwintop.xJavaFxTool.plugin.PluginClassLoader;
98
import com.xwintop.xJavaFxTool.plugin.PluginContainer;
109
import com.xwintop.xJavaFxTool.utils.Config;
1110
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
@@ -141,7 +140,7 @@ public void loadPlugin(PluginJarInfo pluginJarInfo) {
141140
*/
142141
public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane, boolean singleWindowBoot) {
143142
try {
144-
PluginContainer pluginContainer = new PluginContainer(PluginClassLoader.class.getClassLoader(), plugin);
143+
PluginContainer pluginContainer = new PluginContainer(plugin);
145144
FXMLLoader generatingCodeFXMLLoader = pluginContainer.createFXMLLoader();
146145
if (generatingCodeFXMLLoader == null) {
147146
return null;

0 commit comments

Comments
 (0)