0

I cloned this repo and I am trying to compile it because the releases dont work despite it working for everyone else I have talked to. The problem is when I compile it and run it, I get this error.

Exception in thread "main" java.lang.NoClassDefFoundError: com/alee/laf/WebLookAndFeel
        at me.grax.jbytemod.res.LanguageRes.fixUnicodeSupport(LanguageRes.java:33)
        at me.grax.jbytemod.res.LanguageRes.<init>(LanguageRes.java:27)
        at me.grax.jbytemod.JByteMod.initialize(JByteMod.java:173)
        at me.grax.jbytemod.JByteMod.main(JByteMod.java:222)
Caused by: java.lang.ClassNotFoundException: com.alee.laf.WebLookAndFeel
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 4 more

However, when I actually go to the fixUnicodeSupport() method, I dont get any errors inside of InteillJ. The method looks like the following but when I click on WebLookAndFeel and click go-to it takes me to the class.

    private void fixUnicodeSupport() {
        for (String translation : map.values()) {
            for (char c : translation.toCharArray()) {
                if (!WebLookAndFeel.globalControlFont.canDisplay(c)) {
                    WebLookAndFeel.globalControlFont = fixFont(WebLookAndFeel.globalControlFont);
                    WebLookAndFeel.globalTooltipFont = fixFont(WebLookAndFeel.globalTooltipFont);
                    WebLookAndFeel.globalAlertFont = fixFont(WebLookAndFeel.globalAlertFont);
                    WebLookAndFeel.globalMenuFont = fixFont(WebLookAndFeel.globalMenuFont);
                    WebLookAndFeel.globalAcceleratorFont = fixFont(WebLookAndFeel.globalAcceleratorFont);
                    WebLookAndFeel.globalTitleFont = fixFont(WebLookAndFeel.globalTitleFont);
                    WebLookAndFeel.globalTextFont = fixFont(WebLookAndFeel.globalTextFont);
                    JByteMod.LOGGER.log("Updated WebLaF fonts for unicode support");
                    return;
                }
            }
        }
        JByteMod.LOGGER.log("Unicode check finished!");
    }

This project contains the weblaf-complete-1.29-fixed.jar inside the lib folder and I even changed its maven path to the hard coded path which I know exists and everything does compile fine, but I still get that error. I then decided to go into Project Structure -> Libraries and then add the lib to that (which is how you normally do it without maven) but that also did not work. So why exactly am I getting a class not found error when its clearly there since I can visit the class and InteilJ does not show any errors which normally happens when a class is actually missing.

Edit:

I even tried to add the following resource to my pom (the pom is linked above) which does increase the jar's size (since it now included the libs) but I still get the same error.

            <resource>
                <directory>${project.basedir}</directory>
                <includes>
                    <include>lib/*.jar</include>
                </includes>
            </resource>

Edit 2:

My environment variables are set to jdk 8 (both user and for system). However, when I instead run this jar file by doing "C:\Program Files\Java\jdk1.8.0_291\bin\java.exe" -jar JByteMod-Remastered-2.1.4.jar which ensures it is ran with Java 8 I now get a new error.

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

I am not sure why this is happening, but I know attach which is used for hooking vm's in Java has been removed after Java 8 but I already checked, and that jar is still inside my jdk 8. I also included attach-1.7 inside my lib folder which should be shaded into the final jar file. I also know that JNI allows java to access native interfaces and use code from C++ and vis versa. But that does not exactly help me determine what is causing this error.

UnSure
  • 75
  • 6
  • How are you a. building it, and b. running it? – g00se Aug 14 '23 at 18:47
  • @g00se Building it with maven by right clicking package and clicking run. This causes maven to build the jar and place it in the target directory. I run it by going to the directory of the jar and type cmd and then type ``java -jar JByteMod-Remastered-2.1.4.jar`` so that I get a console stack trace of possible issues. – UnSure Aug 14 '23 at 18:49
  • 1
    This does not do so by default in IntelliJ, usually it will build it internally. You'd want to execute a maven goal `mvn clean compile package` first, and see what happens. The rest is up to your `pom.xml` configuration. – Rogue Aug 14 '23 at 19:00
  • Sounds like you need to work on your packaging with Maven. Try the maven-assembly-plugin: https://stackoverflow.com/questions/16222748/building-a-fat-jar-using-maven. I would not mix Maven with /lib. Add the JARs to your local .m2 and call for them in your pom.xml. Install them to a central Maven repo if you need that JAR to be available to others. – duffymo Aug 14 '23 at 19:03
  • @Rogue Ok I tried that and it took longer but worked without any errors, but I still get the same error message. It even says ``Loading JByteMod-Remastered\lib\weblaf-complete-1.29-fixed.jar(com/alee/laf/WebLookAndFeel.class)]``. This has never been an issue before when using external jars with maven so I am not sure why its a problem now. – UnSure Aug 14 '23 at 19:06
  • *I run it by going to the directory of the jar and type cmd and then type java -jar JByteMod-Remastered-2.1.4.jar* that won't cut it unless you've got a fat jar plug-in configured in Maven. Looks like you haven't – g00se Aug 14 '23 at 19:24
  • @duffymo I am not sure where this .m2 folder is at because I dont see it in my projects directory. Maybe its in mavens installation directory but that does not make sense because why would I include my jar files in there when I only want them to be used in this one project. I also dont see why everyone else who has used this repo has been fine so there must be a way to make it work as is. I deleted the added library and tried this again with the same outcome. – UnSure Aug 14 '23 at 19:35
  • @g00se I also tried it by doing ``mvn clean compile package`` with the same outcomes. I did however notice that my jar file's size is smaller than it should by the exact amount of the missing lib. But I am not sure why its not being added. – UnSure Aug 14 '23 at 19:36
  • You didn't post your pom but I suspect you are not using a fat jar plugin. If so just configure one and use it – g00se Aug 14 '23 at 20:04
  • @g00se I did post the pom I linked it in my first sentence. – UnSure Aug 14 '23 at 20:31
  • Sorry - didn't realize you were using it straight from the clone. Shall inspect – g00se Aug 14 '23 at 21:04
  • .m2 is not in your project repository; it's the local directory where Maven will look for dependencies. It's not possible to use Maven without understanding what .m2 is. – duffymo Aug 14 '23 at 21:08
  • I suspect that is only one of *several* problems you're experiencing. [Always post the *full* stack trace](https://technojeeves.com/index.php/aliasjava1/17-errors) That will build and run for me, but *only* with Java 8 ( or probably lower). For one thing, it relies on the JRE scripting support, which was removed in later versions. – g00se Aug 14 '23 at 21:12
  • @g00se I did post the complete stack trace (theres no other errors or missing components). Also, I am in fact using Java 8 (to compile the project and on my pc since its set as my javas home) but like I said many other people have been able to use this successfully, so I don't see the issue. I am also not getting any compilation errors. – UnSure Aug 14 '23 at 21:14
  • OK. If you're *certain* you're using a Java 8 compiler then go to the command line and do: `mvn clean package` followed by `java -jar weblaf-complete-1.29-fixed.jar` (Note the version number) That ends up in /tmp for me – g00se Aug 14 '23 at 21:22
  • @g00se Where do I type the ``weblaf`` command? I type ``mvn clean package`` in the directory of JByteMod-Remastered but typing ``java -jar weblaf-complete-1.29-fixed.jar`` in that same cmd results in ``Error: Unable to access jarfile weblaf-complete-1.29-fixed.jar``. DO you instead want me to type ``cmd`` inside the libs folder and then type that command? Because doing that results in errors but I am not sure where this /tmp is. – UnSure Aug 14 '23 at 21:27
  • Sorry - that was wrong! This is what happens for me (so this will guide you to the right name) Love the way Shade gets its names the wrong way around: `[INFO] Replacing /tmp/JByteMod-Remastered/target/JByteMod-Remastered-2.1.4.jar with /tmp/JByteMod-Remastered/target/JByteMod-Remastered-2.1.4-shaded.jar` So the correct jar is the one *without* the substring 'shaded' in its name. For you it might be in a different place since I run Maven from the /tmp tree. You will see that message or similar towards the end of your whole output – g00se Aug 14 '23 at 21:31
  • @g00se The jars in lib were not actually getting shaded until I added the above resource edit (check my original post). But after making that fix my jar got larger by the size of weblaf. That being said maven right now just compiles me the shaded version which does not contain ``-shaded`` in the name. Without that change I never get a shaded version. That being said I am having a hard time understanding what you are wanting me to do. – UnSure Aug 14 '23 at 21:37
  • There's definitely no reason to change anything. There are some 'problems' that get warned about by Maven but they are probably not relevant to your current issue. I would start by deleting your cloned repo and reclone it. You could use Git to avoid that but I'd play safe and do the deletion – g00se Aug 14 '23 at 21:46
  • @g00se I think I fixed that one issue thanks to looking into one of your suggestions, but I ran into a new issue. Check my posts Edit 2 for the new issue. Also, I appreciate you trying to help. – UnSure Aug 14 '23 at 21:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254913/discussion-between-g00se-and-unsure). – g00se Aug 14 '23 at 22:09

0 Answers0