`Files.createSymbolicLink` in Java Snippet problem

hi, there, :grinning:

(After search,) I know KNIME cannot create symbolic link of file with node. So I want to do this by Java Snippet, but without luck.

All the workflow is simple, create a res.csv in desktop, and want to create symbolic link res.lnk (In Windows 10).

java_createSymbolicLink_problem.knwf (15.9 KB)

This main java snippet is also simple.

try{

Path source = Paths.get(desktop_path+ "\\res.csv");
Path link = Paths.get(desktop_path+ "\\res.lnk"); // symbolic link's absolute path
Files.createSymbolicLink(link, source); // create symbolic link.

} catch (IOException ioex) {
 ioex.printStackTrace();
}catch(Exception e){
 e.printStackTrace();
 System.out.println(e);
}

After execution, nothing happens.

Do somebody know what I’m missing?

Thanks in advance!

Hi,

obviously an exception is thrown but with this code you’ll not see the actual error, because println or printStackTrace will not print to the KNIME log output. Replace the code in the catch parts with logError or (better imo) re-throw the exception to ensure that the node actually fails on failures – there’s an Abort exception class which you can use, see here:

try {
   // …
} catch (Exception e) {
   throw new Abort(e);
}

This should give you a proper error reporting to find out what’s actually going wrong.

– Philipp

4 Likes

If you do want to print to the KNIME console (and have execution continue), use:

try{
    //..
} catch (Exception e) {
    NodeLogger.getLogger("Broken Snippet").warn(e.getMessage());
}

Steve

3 Likes

:heart: @qqilihq @s.roughley :heart:

you saved my life, thanks!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.