Index: /applications/editors/josm/plugins/simple/build.xml
===================================================================
--- /applications/editors/josm/plugins/simple/build.xml	(revision 23119)
+++ /applications/editors/josm/plugins/simple/build.xml	(revision 23119)
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+** This is a template build file for a JOSM  plugin.
+**
+** Maintaining versions
+** ====================
+** see README.template
+**
+** Usage
+** =====
+** To build it run
+**
+**    > ant  dist
+**
+** To install the generated plugin locally (in you default plugin directory) run
+**
+**    > ant  install
+**
+** The generated plugin jar is not automatically available in JOSMs plugin configuration
+** dialog. You have to check it in first.
+**
+** Use the ant target 'publish' to check in the plugin and make it available to other
+** JOSM users:
+**    set the properties commit.message and plugin.main.version
+** and run
+**    > ant  publish
+**
+**
+-->
+<project name="simple" default="dist">
+
+	<!--
+      ************************************************
+      ** should not be necessary to change the following properties
+     -->
+	<property name="toms"					location="../../dist/toms.jar/"/>
+ 	<property name="plugin.build.dir"       value="build"/>
+	<property name="plugin.src.dir"         value="src"/>
+	<!-- this is the directory where the plugin jar is copied to -->
+	<property name="plugin.dist.dir"        value="../../dist"/>
+	<property name="ant.build.javac.target" value="1.5"/>
+	<property name="plugin.dist.dir"        value="../../dist"/>
+	<property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
+
+	<!--
+    **********************************************************
+    ** init - initializes the build
+    **********************************************************
+    -->
+	<target name="init">
+		<mkdir dir="${plugin.build.dir}"/>
+	</target>
+
+	<!--
+    **********************************************************
+    ** compile - compiles the source tree
+    **********************************************************
+    -->
+	<target name="compile" depends="init">
+		<echo message="compiling sources for  ${plugin.jar} ... "/>
+		<javac srcdir="src" classpath="${toms}" debug="true" destdir="${plugin.build.dir}">
+			<compilerarg value="-Xlint:deprecation"/>
+			<compilerarg value="-Xlint:unchecked"/>
+		</javac>
+	</target>
+	
+	<target name="dist" depends="compile">
+		<echo message="creating ${ant.project.name}.jar ... "/>
+		<jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">
+			<!--
+        ************************************************
+        ** configure these properties. Most of them will be copied to the plugins
+        ** manifest file. Property values will also show up in the list available
+        ** plugins: http://josm.openstreetmap.de/wiki/Plugins.
+        **
+        ************************************************
+    -->
+			<manifest>
+				<attribute name="Author" value="Werner, Malcolm"/>
+				<attribute name="Plugin-Class" value="ifc.Pluggable"/>
+				<attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
+				<attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
+				<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
+			</manifest>
+		</jar>
+	</target>
+	
+	<!--
+    **********************************************************
+    ** install - install the plugin in your local JOSM installation
+    **********************************************************
+    -->
+	<target name="install" depends="dist">
+		<property environment="env"/>
+		<condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
+			<and>
+				<os family="windows"/>
+			</and>
+		</condition>
+		<copy file="${plugin.jar}" todir="${josm.plugins.dir}/tplug"/>
+	</target>
+
+</project>
Index: /applications/editors/josm/plugins/simple/src/simple/SimplePlugin.java
===================================================================
--- /applications/editors/josm/plugins/simple/src/simple/SimplePlugin.java	(revision 23119)
+++ /applications/editors/josm/plugins/simple/src/simple/SimplePlugin.java	(revision 23119)
@@ -0,0 +1,28 @@
+package simple;
+
+import toms.plug.ifc.Pluggable;
+import toms.plug.ifc.PluginManager;
+
+public class SimplePlugin implements Pluggable {
+
+	private PluginManager manager; 
+	
+	@Override
+	public boolean start() {
+		this.manager.showVisualMessage("Started!");
+		return true;
+	}
+
+	@Override
+	public boolean stop() {
+		this.manager.showVisualMessage("Stopped!");
+		return true;
+	}
+
+	@Override
+	public void setPluginManager(PluginManager manager) {
+		this.manager = manager;		this.manager = manager;
+		
+	}
+
+}
Index: /applications/editors/josm/plugins/toms/build.xml
===================================================================
--- /applications/editors/josm/plugins/toms/build.xml	(revision 23118)
+++ /applications/editors/josm/plugins/toms/build.xml	(revision 23119)
@@ -113,4 +113,5 @@
 				<attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
 				<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
+				<attribute name="Class-Path" value="./tplug/ifc.jar"/>
 			</manifest>
 		</jar>
Index: /applications/editors/josm/plugins/toms/src/toms/Toms.java
===================================================================
--- /applications/editors/josm/plugins/toms/src/toms/Toms.java	(revision 23118)
+++ /applications/editors/josm/plugins/toms/src/toms/Toms.java	(revision 23119)
@@ -8,6 +8,25 @@
 
 import java.awt.event.KeyEvent;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
 
 import javax.swing.JMenuItem;
@@ -23,4 +42,6 @@
 import toms.dialogs.SmpDialogAction;
 import toms.plug.PluginApp;
+import toms.plug.ifc.Pluggable;
+import toms.plug.util.PluginLoader;
 import toms.seamarks.SeaMark;
 
@@ -48,7 +69,76 @@
 		SmpDialog.setUserHome(userHome);
 		Smp.setEnabled(false);
+
+		File pluginDir = Main.pref.getPluginsDirectory();
+		String pluginDirName = pluginDir.getAbsolutePath();
+		File tplug = new File(pluginDirName + "/tplug");
+		if(!tplug.exists()) tplug.mkdir();
 		
-		PluginApp.runPlugins();
+		// build ifc.jar from toms.jar
+		JarEntry ent = null;
+		BufferedInputStream inp = null;
+		String entName = null;
+		byte[] buffer = new byte[16384];
+		int len;
+
+		try {
+			JarFile file = new JarFile(pluginDirName  + "/toms.jar");			
+			FileOutputStream fos = new FileOutputStream(pluginDirName + "/tplug/ifc.jar");			
+			JarOutputStream jos = new JarOutputStream(fos);
+			BufferedOutputStream oos = new BufferedOutputStream( jos);
+
+			ent = file.getJarEntry("toms/plug/ifc/Pluggable.class");
+			inp = new BufferedInputStream(file.getInputStream( ent ));
+			entName = ent.getName();
+
+			jos.putNextEntry(new JarEntry(entName));
+			
+		    while ((len = inp.read(buffer)) > 0) {
+		    	oos.write(buffer, 0, len);
+            }
+
+		    oos.flush();
+		    inp.close();
+	    
+		    ent = file.getJarEntry("toms/plug/ifc/PluginManager.class");
+		    inp = new BufferedInputStream(file.getInputStream( ent ));
+		    entName = ent.getName();
+		    jos.putNextEntry(new JarEntry(entName));
+		    
+		    while ((len = inp.read(buffer)) > 0) {
+		    	oos.write(buffer, 0, len);
+            }
+
+			oos.flush();
+			oos.close();
+		    fos.flush();
+		    fos.close();
+		    inp.close();
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+		} 
+		
+		
+		// add ifc.jar to classpath (josm need this archive, or perhaps only the interface)
+		File f = new java.io.File(pluginDirName + "/tplug/ifc.jar");
+		ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader();
+
+		try {
+			Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
+			addUrlMethod.setAccessible(true);
+			addUrlMethod.invoke(myClassLoader, f.toURI().toURL());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		
+		try {
+			PluginApp.runPlugins();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
 	}
+
 
 	@Override
Index: /applications/editors/josm/plugins/toms/src/toms/plug/PluginApp.java
===================================================================
--- /applications/editors/josm/plugins/toms/src/toms/plug/PluginApp.java	(revision 23118)
+++ /applications/editors/josm/plugins/toms/src/toms/plug/PluginApp.java	(revision 23119)
@@ -2,14 +2,36 @@
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
+import org.openstreetmap.josm.Main;
+
+
 import toms.plug.ifc.Pluggable;
+import toms.plug.ifc.PluginManager;
 import toms.plug.util.PluginLoader;
 
 public class PluginApp {
 	
-	public static void runPlugins() {
-		List<Pluggable> plugins = PluginLoader.loadPlugins(new File("./tplug"));
-		System.out.println("hello world");
+	public static void runPlugins() throws IOException {
+		String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath();
+
+		List<Pluggable> plugins = PluginLoader.loadPlugins(new File(pluginDirName + "/tplug"));
+
+		if(plugins == null) return;
+		
+		PluginManager manager = new PluginManagerImpl();
+		
+		for(Pluggable p : plugins) p.setPluginManager(manager);
+		for(Pluggable p : plugins) p.start();
+		
+		// wait
+		try {
+			Thread.sleep(10000);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+		
+		for(Pluggable p: plugins) p.stop();
 	}
 
Index: /applications/editors/josm/plugins/toms/src/toms/plug/util/PluginLoader.java
===================================================================
--- /applications/editors/josm/plugins/toms/src/toms/plug/util/PluginLoader.java	(revision 23118)
+++ /applications/editors/josm/plugins/toms/src/toms/plug/util/PluginLoader.java	(revision 23119)
@@ -2,13 +2,104 @@
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
 
 import toms.plug.ifc.Pluggable;
 
+
 public class PluginLoader {
 
-	public static List<Pluggable> loadPlugins(File file) {
-		System.out.println("Hier ist der PluginLoader");
-		return null;
+	public static List<Pluggable> loadPlugins(File plugDir) throws IOException {
+		File[] plugJars = plugDir.listFiles(new JARFileFilter());
+		ClassLoader cl = new URLClassLoader(PluginLoader.fileArrayToURLArray(plugJars));
+		
+		if(cl == null) return null;
+		
+		List<Class<Pluggable>> plugClasses = PluginLoader.extractClassesFromJARs(plugJars, cl);
+		
+		return PluginLoader.createPluggableObjects(plugClasses);
+	}
+
+	private static List<Pluggable> createPluggableObjects(List<Class<Pluggable>> pluggables) {
+		List<Pluggable> plugs = new ArrayList<Pluggable>(pluggables.size());
+		for(Class<Pluggable> plug : pluggables) {
+			try {
+				plugs.add(plug.newInstance());
+			} catch (InstantiationException e) {
+				System.err.println("Can't instantiate plugin: " + plug.getName());
+				e.printStackTrace();
+			} catch (IllegalAccessException e) {
+				System.err.println("IllegalAccess for plugin: " + plug.getName());
+				e.printStackTrace();
+			}
+		}
+		
+		return plugs;
+
+	}
+
+	private static List<Class<Pluggable>> extractClassesFromJARs(	File[] jars, ClassLoader cl) throws FileNotFoundException, IOException {
+		List<Class<Pluggable>> classes = new ArrayList<Class<Pluggable>>();
+		
+		for(File jar : jars) {
+			classes.addAll(PluginLoader.extractClassesFromJAR(jar, cl));
+		}
+
+		return classes;
+	}
+
+	@SuppressWarnings("unchecked")
+	private static Collection<? extends Class<Pluggable>> extractClassesFromJAR(File jar, ClassLoader cl) throws FileNotFoundException, IOException {
+		List<Class<Pluggable>> classes = new ArrayList<Class<Pluggable>>();
+		JarInputStream jaris = new JarInputStream(new FileInputStream(jar));
+		JarEntry ent = null;
+		
+		while ((ent = jaris.getNextJarEntry()) != null) {
+			String entName = ent.getName(); //.toLowerCase();
+			
+			if (entName.endsWith(".class")) {
+				try {
+					Class<?> cls = cl.loadClass(entName.substring(0, entName.length()- 6).replace('/', '.'));
+					if (PluginLoader.isPluggableClass(cls)) classes.add((Class<Pluggable>) cls);
+				} catch (ClassNotFoundException e) {
+					System.err.println("Can't load Class" + entName);
+					e.printStackTrace();
+				}
+			}
+		}
+		
+		jaris.close();
+		
+		return classes;
+	}
+
+	private static boolean isPluggableClass(Class<?> cls) {
+		for (Class<?> i: cls.getInterfaces()) {
+			if (i.equals(Pluggable.class)) return true;
+		}
+		
+		return false;
+
+	}
+
+	private static URL[] fileArrayToURLArray(File[] files) throws MalformedURLException {
+		URL[] urls = new URL[files.length];
+		
+		if(urls == null) return null;
+		
+		for(int i = 0; i < files.length; i++) {
+			urls[i] = files[i].toURI().toURL();
+		}
+		
+		return urls;
 	}
 
