From a27c3540994bf3c5188baab45d1012af653cb00d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 13 Nov 2019 17:09:20 +0100 Subject: Get rid of class loader hack, use command line instead --- .../src/main/java/org/openslx/taskmanager/App.java | 20 ------------ .../openslx/taskmanager/util/ClassLoaderHack.java | 36 ---------------------- daemon/taskmanager.sh | 8 +++++ 3 files changed, 8 insertions(+), 56 deletions(-) create mode 100755 daemon/taskmanager.sh diff --git a/daemon/src/main/java/org/openslx/taskmanager/App.java b/daemon/src/main/java/org/openslx/taskmanager/App.java index c7dfa18..6b281d6 100644 --- a/daemon/src/main/java/org/openslx/taskmanager/App.java +++ b/daemon/src/main/java/org/openslx/taskmanager/App.java @@ -1,7 +1,5 @@ package org.openslx.taskmanager; -import java.io.File; -import java.io.IOException; import java.net.SocketException; import java.util.ArrayList; import java.util.List; @@ -10,7 +8,6 @@ import org.apache.log4j.BasicConfigurator; import org.openslx.taskmanager.main.Taskmanager; import org.openslx.taskmanager.network.NetworkHandler; import org.openslx.taskmanager.network.RequestParser; -import org.openslx.taskmanager.util.ClassLoaderHack; /** * Hello world! @@ -23,23 +20,6 @@ public class App { BasicConfigurator.configure(); // Load all task plugins - Thread.currentThread().setContextClassLoader( ClassLoader.getSystemClassLoader() ); - File folder = new File( "./plugins" ); - if ( !folder.exists() ) { - System.out.println( "No plugin folder found - nothing to do." ); - System.exit( 1 ); - } - for ( File file : folder.listFiles() ) { - if ( !file.isFile() || !file.toString().endsWith( ".jar" ) ) - continue; - try { - ClassLoaderHack.addFile( file ); - } catch ( IOException e ) { - e.printStackTrace(); - System.out.println( "Could not add plugin: " + file.toString() ); - System.exit( 1 ); - } - } Environment.load( "config/environment" ); List threads = new ArrayList<>(); Taskmanager tm = new Taskmanager(); diff --git a/daemon/src/main/java/org/openslx/taskmanager/util/ClassLoaderHack.java b/daemon/src/main/java/org/openslx/taskmanager/util/ClassLoaderHack.java index 0a3160c..2557fcb 100644 --- a/daemon/src/main/java/org/openslx/taskmanager/util/ClassLoaderHack.java +++ b/daemon/src/main/java/org/openslx/taskmanager/util/ClassLoaderHack.java @@ -1,43 +1,7 @@ package org.openslx.taskmanager.util; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; - public class ClassLoaderHack { - @SuppressWarnings( "rawtypes" ) - private static final Class[] parameters = new Class[] { URL.class }; - - public static void addFile( String s ) throws IOException - { - File f = new File( s ); - addFile( f ); - } - - public static void addFile( File f ) throws IOException - { - addURL( f.toURI().toURL() ); - } - - public static void addURL( URL u ) throws IOException - { - URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader(); - Class sysclass = URLClassLoader.class; - - try { - Method method = sysclass.getDeclaredMethod( "addURL", parameters ); - method.setAccessible( true ); - method.invoke( sysloader, new Object[] { u } ); - System.out.println( "Loaded " + u.toString() ); - } catch ( Throwable t ) { - t.printStackTrace(); - throw new IOException( "Error, could not add URL to system classloader" ); - } - - } /** * Get Class meta-object for given class in package. Only return class if it's somehow diff --git a/daemon/taskmanager.sh b/daemon/taskmanager.sh new file mode 100755 index 0000000..269701d --- /dev/null +++ b/daemon/taskmanager.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +jars= +for i in plugins/*.jar; do + jars="${jars}:$i" +done +exec java -Xmx80M -cp "taskmanager.jar${jars}" org.openslx.taskmanager.App + -- cgit v1.2.3-55-g7522