Ray 3 years ago
parent
commit
2d66568c7d

+ 10 - 0
.classpath

@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="src" path="src"/>
4
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5
+	<classpathentry kind="lib" path="C:/Users/msn/Documents/workspaces/eclipse workspace/BaseToolWithExternJars/Prog1.jar"/>
6
+	<classpathentry kind="lib" path="C:/Users/msn/Documents/workspaces/eclipse workspace/BaseToolWithExternJars/Prog2.jar"/>
7
+	<classpathentry kind="lib" path="C:/Users/msn/Documents/workspaces/eclipse workspace/BaseToolWithExternJars/Prog3.jar"/>
8
+	<classpathentry kind="lib" path="C:/Users/msn/Documents/workspaces/eclipse workspace/BaseToolWithExternJars/Prog4.jar"/>
9
+	<classpathentry kind="output" path="bin"/>
10
+</classpath>

+ 17 - 0
.project

@@ -0,0 +1,17 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>BaseToolWithExternJars</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+	</buildSpec>
14
+	<natures>
15
+		<nature>org.eclipse.jdt.core.javanature</nature>
16
+	</natures>
17
+</projectDescription>

+ 11 - 0
.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
1
+eclipse.preferences.version=1
2
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5
+org.eclipse.jdt.core.compiler.compliance=1.8
6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
8
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11
+org.eclipse.jdt.core.compiler.source=1.8

BIN
Prog1.jar


BIN
Prog2.jar


BIN
Prog3.jar


BIN
Prog4.jar


BIN
bin/baseTool/BaseTool.class


BIN
bin/baseTool/Interface.class


+ 46 - 0
src/baseTool/BaseTool.java

@@ -0,0 +1,46 @@
1
+package baseTool;
2
+
3
+import java.lang.reflect.InvocationTargetException;
4
+import java.lang.reflect.Method;
5
+
6
+import rainer_prog1.Prog1;
7
+import rainer_prog2.Prog2;
8
+import rainer_prog3.Prog3;
9
+import rainer_prog4.Prog4;
10
+
11
+public class BaseTool {
12
+
13
+	public static void starten(Class<?> programm, String schnittstelle, String methode, String ... params){
14
+		boolean interfaceGefunden = false;
15
+		
16
+		// Alle Interfaces auslesen
17
+		Class<?>[] classes = programm.getInterfaces();
18
+		
19
+		// Alle Interfaces iterieren
20
+		for(Class<?> c : classes){
21
+			// Nach dem Interface Namen suchen
22
+			if(c.getSimpleName().equals(schnittstelle)){
23
+				interfaceGefunden = true;
24
+			}
25
+		}
26
+		
27
+		if(interfaceGefunden){
28
+			try {
29
+				// Die Methode im Interface suchen, jedoch aus Klasse nehmen (nicht aus dem Interface)
30
+				Method m = programm.getDeclaredMethod(methode, null);
31
+				
32
+				// Implementierte Methode aus der Klasse ausführen (ggf. mit Parameter für die Methode)
33
+				m.invoke(programm.newInstance(), params);	
34
+			} catch (Exception e) {
35
+				e.printStackTrace();
36
+			}
37
+		}
38
+	}
39
+	
40
+	public static void main(String[] args) {
41
+		starten(Prog1.class, "Interface", "progStarten");
42
+		starten(Prog2.class, "Interface", "progStarten");
43
+		starten(Prog3.class, "Interface", "progStarten");
44
+		starten(Prog4.class, "Interface", "progStarten");
45
+	}
46
+}

+ 5 - 0
src/baseTool/Interface.java

@@ -0,0 +1,5 @@
1
+package baseTool;
2
+
3
+public interface Interface {
4
+		public void progStarten();
5
+}