Переглянути джерело

Merge branch 'feature/java11' into 'develop'

fix

See merge request o2oa/o2oa!1519
o2null 5 роки тому
батько
коміт
9ab3ba11e3

+ 1 - 1
o2server/start_linux.sh

@@ -148,4 +148,4 @@ if [ -d ${current_dir}/local/update ]; then
 		rm -Rf ${current_dir}/local/update
 	fi
 fi
-setsid ${current_dir}/jvm/linux/bin/java -server -Djava.awt.headless=true -Xms2g -Xmx5g -Duser.timezone=GMT+08 -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -jar ${current_dir}/console.jar
+setsid ${current_dir}/jvm/linux/bin/java -javaagent:${current_dir}/console.jar -server -Djava.awt.headless=true -Xms2g -Xmx5g -Duser.timezone=GMT+08 -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -jar ${current_dir}/console.jar

+ 22 - 3
o2server/x_console/src/main/java/com/x/server/console/InstrumentationAgent.java

@@ -35,14 +35,14 @@ public class InstrumentationAgent {
 			if (Files.exists(base.resolve(DYNAMIC_JARS))) {
 				load(base, DYNAMIC_JARS);
 			}
-			load(base, STORE_JARS);
-			load(base, COMMONS_EXT);
+			loadWithCfg(base, STORE_JARS);
+			loadWithCfg(base, COMMONS_EXT);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 	}
 
-	private static void load(Path base, String sub) throws IOException {
+	private static void loadWithCfg(Path base, String sub) throws IOException {
 		Path dir = base.resolve(sub);
 		Path cfg = dir.resolve(CFG);
 		if (Files.exists(dir) && Files.isDirectory(dir) && Files.exists(cfg) && Files.isRegularFile(cfg)) {
@@ -74,6 +74,25 @@ public class InstrumentationAgent {
 		}
 	}
 
+	private static void load(Path base, String sub) throws IOException {
+		Path dir = base.resolve(sub);
+		if (Files.exists(dir) && Files.isDirectory(dir)) {
+			try (Stream<Path> stream = Files.list(dir)) {
+				stream.filter(
+						o -> o.toString().toLowerCase().endsWith(".zip") || o.toString().toLowerCase().endsWith(".jar"))
+						.forEach(o -> {
+							try {
+								INST.appendToSystemClassLoaderSearch(new JarFile(o.toString()));
+							} catch (IOException e) {
+								e.printStackTrace();
+							}
+						});
+			}
+		} else {
+			throw new IOException(String.format("invalid directory: %s", sub));
+		}
+	}
+
 	private static Path getBasePath() throws IOException, URISyntaxException {
 		Path path = Paths.get(InstrumentationAgent.class.getProtectionDomain().getCodeSource().getLocation().toURI());
 		Path version = path.resolveSibling("version.o2");