Edit: this is the Project Setup:
IDE: Eclipse:
Project1 : "Server"
src:
com/mainpackage/main.java
libs:
commons-x-0.jar
PluginInterface.jar
all jar in libs-folder are on the buildpath.
Project2 : "PluginInterface"
src:
com/interfaces/plugininterface
Project3 : "Plugin"
src:
com/package/class1.java - (this implements plugininterface)
libs:
library1.jar
PluginInterface.jar
all jar in libs-folder are on the buildpath
so when i export the Plugin (Project3) i get a jar like this (excluded PluginInterface.jar from export)
com/
com/package/
com/package/class1.class
com/package/class1.java
libs/
libs/library1.jar
library1.jar looks as follows - it is not written by me:
com/
com/stuff/
com/stuff/libclass.java
com/stuff/libclass.class
now i Want to utilize class1 in the "Server" over the Interface:
ClassLoader loader=URLClassLoader.newInstance(
new URL[]{new URL("file:path/to/plugin.jar")},
ClassLoader.getSystemClassLoader()
);
Class<?> pluginclass = Class.forName("com.package.class1", true, loader);
plugininterface ref = (plugininterface)pluginclass.newInstance();
i can now call methods from class1 using the interface both projects know, because both of them include "PluginInterface.jar" in their buildpath.
THE PROBLEM:
"Server" does not recognize "libclass", because is neither in its path nor did i load the class from the plugin.jar in which the library1 is nested.
how do i access this class if an import as library is not possible at the server?
Thanks for any help!
Edit: just for the sake if someone ever has this Problem again, i'll add the ANT files' build-target that makes it work:
<target name="build">
<javac destdir="bin" includeantruntime="false" source="1.7" target="1.7">
<src path="src"/>
<classpath refid="Plugin.classpath"/>
</javac>
<unzip src="${libs}/library1.jar" dest="bin/">
<patternset>
<include name="**/*.class"/>
</patternset>
</unzip>
<jar destfile="plugin.jar" basedir="bin"></jar>
</target>
Just copy the contents of the Library-jar into the build directory (in my case ./bin/). it then isn't even necessary to feed the libraryclasses to the Classloader, it finds them when loading the Classes use them.