Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException When Importing a Java Class in LuaJava #200

Closed
Keurig-Creator opened this issue Aug 22, 2024 · 1 comment · Fixed by #202
Closed

ClassNotFoundException When Importing a Java Class in LuaJava #200

Keurig-Creator opened this issue Aug 22, 2024 · 1 comment · Fixed by #202
Assignees
Labels
bug Something isn't working

Comments

@Keurig-Creator
Copy link

Describe the Bug
I am encountering a ClassNotFoundException when attempting to import a Java class into Lua using LuaJava within a Spigot plugin. The error occurs even though the class path appears to be correct, as evidenced by a hyperlink in the console that directly opens the class. The issue is not related to Android, as I am not using it.

To Reproduce
Steps to reproduce the behavior:

Set up a Spigot plugin project with LuaJava as a dependency.

Use the following LuaJava code to import a Java class:

try (Lua lua = new Lua51()) {
    lua.openLibraries();
    lua.run("Chat = java.import('com.keurig.luaplugin.Chat')");
    lua.run("Chat:log('Test from lua')");
} catch (Exception e) {
    e.printStackTrace();
}

Run the plugin and observe the ClassNotFoundException in the console.

Verify the com.keurig.luaplugin.Chat class is present in the project and accessible.

Current Behavior
The ClassNotFoundException is thrown despite the class being present and the class path seemingly correct. The error does not provide any clear indication of why the class cannot be found.

Expected Behavior
The class com.keurig.luaplugin.Chat should be successfully imported into Lua, allowing the script to interact with the class as expected.

Platform

Arch: x86_64
OS: Windows 11
JDK: 17
Gradle Version: 8.10
LuaJava Version: 4.0.1
Spigot Version: 1.21
Additional Context:
I am using Gradle for this project. Here is my build.gradle configuration:
Link to build.gradle:

This issue may be related to how LuaJava handles class loading, potentially involving the system classloader. I have reviewed several resources, including those specific to Android, but I am not using Android for this project.

Thank you for your assistance in resolving this issue.

@gudzpoz
Copy link
Owner

gudzpoz commented Aug 29, 2024

I just release a v4.0.2 with a fix, can you please try it out?

Also, when debugging I discovered that the Gradle plugin shadow does not prune META-INF/versions/9/module-info.class from the dependencies, which might still cause problems. So you might want to find a way to exclude these module-info.class with some shadow options. (https://gudzpoz.github.io/luajava/troubleshooting.html#are-you-mistakenly-using-java-9-modules)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants