Skip to content

Commit

Permalink
1.修改类加载器bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xwintop committed Apr 2, 2022
1 parent 9249c7c commit 1858d5f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@

<!-- https://mvnrepository.com/artifact/io.github.classgraph/classgraph -->
<!-- https://github.com/classgraph/classgraph -->
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.100</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.github.classgraph</groupId>-->
<!-- <artifactId>classgraph</artifactId>-->
<!-- <version>4.8.100</version>-->
<!-- </dependency>-->
</dependencies>
<build>
<plugins>
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/xwintop/xJavaFxTool/plugin/PluginClassLoader.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.xwintop.xJavaFxTool.plugin;

import io.github.classgraph.ClassGraph;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;

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

public static PluginClassLoader create(ClassLoader parent, File jarFile) {
List<URI> uris = new ArrayList<>(new ClassGraph().getClasspathURIs());
uris.add(jarFile.toURI());

URL[] urls = uris.stream().map(uri -> {
try {
return uri.toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}).toArray(URL[]::new);

// List<URI> uris = new ArrayList<>(new ClassGraph().getClasspathURIs());
// uris.add(jarFile.toURI());
// URL[] urls = uris.stream().map(uri -> {
// try {
// return uri.toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// }).toArray(URL[]::new);

URL[] urls = null;
try {
urls = new URL[]{jarFile.toURI().toURL()};
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
return new PluginClassLoader(urls, parent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.xwintop.xJavaFxTool.common.logback.ConsoleLogAppender;
import com.xwintop.xJavaFxTool.controller.IndexController;
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
import com.xwintop.xJavaFxTool.plugin.PluginClassLoader;
import com.xwintop.xJavaFxTool.plugin.PluginContainer;
import com.xwintop.xJavaFxTool.utils.Config;
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
Expand Down Expand Up @@ -141,7 +140,7 @@ public void loadPlugin(PluginJarInfo pluginJarInfo) {
*/
public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane, boolean singleWindowBoot) {
try {
PluginContainer pluginContainer = new PluginContainer(PluginClassLoader.class.getClassLoader(), plugin);
PluginContainer pluginContainer = new PluginContainer(plugin);
FXMLLoader generatingCodeFXMLLoader = pluginContainer.createFXMLLoader();
if (generatingCodeFXMLLoader == null) {
return null;
Expand Down

0 comments on commit 1858d5f

Please sign in to comment.