Search code examples
javashortcut

Java Error "Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: mslinks/ShellLink"


I'm attempting to use ShellLink (Found at https://github.com/DmitriiShamrikov/mslinks/releases) to create shortcuts for some .exe files I'm moving around in my coding

public static void createShortcut(String folder, String system) throws IOException
{
    //Folder is where the .exe is. Linking directly to the .exe not the folder it's in
    //system is the desktop of the user's computer. I've tried both linking it to the folder and a .lnk file. 
    ShellLink.createLink(folder, system); 
    //ShellLink mslinks.ShellLink.createLink(String target, String linkpath)
}

Error

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: mslinks/ShellLink

Error points to

createShortcut(Shortcut+"\\UniversalDesktop.exe", "C:\\Users\\" + Username + "\\Desktop\\" + selectedSystem + ".lnk");

Perhaps there is a better way to create shortcuts via Java programming? Note the .JAR for ShellLink is in my JRE System Library using import mslinks.ShellLink;. I'm at a loss of what is causing the error to appear


Solution

  • I had the JRE in Modulepath instead of Classpath. This caused the error