Doubt with execute a (.jar) archive from ¨configure¨ method

Hi KNIME community, I am a novel developer in Java and recently start working with KNIME. I have a doubt with a new functionality that I should include in a node and it consists in executing a file (.jar) from the method ¨configure¨. It is possible this?, I would thank a lot some help. Regards
Pdta: sorry my english!!


Hi René,

You mean "execute" as something like:

new ProcessBuilder("java", "-jar", "yourJarFile.jar").start();

You can do that even in configure, but unless you need to start a new JVM, I would just use the jar's functionality from the OSGi bundle you have for the node.

Cheers, gabor

Thank's for you answer gabor, but could you be more specifc about jar's functionality from the OSGi bundle. The problem I guess is more related to relative paths, the (.jar) that I want to execute is on SpaceT/visual/spacet.jar rute in the project, how can I execute it using new ProcessBuilder("java", "-jar", "yourJarFile.jar").start(); since relative paths. Thank's again for you help!!

For the OSGi bundle solution please check this FAQ element.

The other one (with the processbuilder) is more tricky. By default when you export the plugin, upon installation it does not expand the archive, so in that case this would not an option (with features), but there is an option that allows you to do this: Unpack the plug-in archive after installation. After that you can find the path using the bundle activator class (using BundleContext in the start method).

Hi again, since the last post about this topic i had tried many ways to solve this problem, but nothing. I can see the content of the jar, unpacking it with Winrar or Winzip, but when I use the Activator class, it returns the file sonce the directory where is the eclipse sdk: "eclipse_knime 2.5.2".

Here are two examples but non of  them gave the file in: G:\Referencias para el trabajo de Diploma\René\Materiales Soft\knime_2.5.2\plugins\ since i want to extract the file "spacetree.jar" that is in the path: \SpaceTreeVizualization\visualización\spacetree-1.6\spacetree.jar, inside the project.

 --This ways gave me the file: G:/workspace_eclipse_knime/SpaceTreeVizualization/visualización/spacetree-1.6/spacetree.jar. Both ways work fine since eclipse, but when I export as a Deployable plug-ins and fragments  and copy it in the directory of knime: G:\Referencias para el trabajo de Diploma\René\Materiales Soft\knime_2.5.2\plugins\, dont work. Sorry if I dont understud but could you show me an example of solution for this.

Anything you need to understand better please ask me. Thank's again



            URL proURL = SpaceTreeNodeModel.class.getProtectionDomain().getCodeSource().getLocation();
            String camino_1 = proURL.getPath() + "visualización/spacetree-1.6/spacetree.jar";
            Path path = new Path(camino_1);            
            Path relativePath = (Path) path.makeAbsolute();
                ProcessBuilder SpaceTreeProcess = new ProcessBuilder("java", "-jar",     relativePath.makeAbsolute().toString());

}catch (IOException ex) {
            Logger.getLogger(Class.class.getName()).log(Level.SEVERE, null, ex);


        org.osgi.framework.Bundle bundle = Activator.getDefault().getBundle("");
        Path path = new Path("/visualización/spacetree-1.6/spacetree.jar");
        URL url = FileLocator.find(bundle, path, null);
        URL fileUrl = null;
        try {    
            fileUrl = FileLocator.toFileURL(url);
        catch (IOException e) {
                // Will happen if the file cannot be read for some reason
            File file = new File(fileUrl.getPath());
            new ProcessBuilder("java", "-jar", file.getPath()).start();