Jump to content
Excelsior Forums
Sign in to follow this  
everybody

NoClassDefFoundException when System.loadLibrary in main class

Recommended Posts

In my very simple test project i had a static System.loadLibrary block in my main class.

Building the project with JET  worked right away, but running throwed a

NoClassDefFoundException on my main class. Moving the static block to another class solved the problem immediatly. It took me some time to figure this out, because the error message is very misleading.

My search in the forum on this issue returned no results, so i am doing this post.

Anyway, JET is a great product and makes code execution more than twice as fast on my computer. Because i am working a lot with long primitive datatypes, I have a further question. Can JET compile for 64-Bit systems?

Kind regards.

Share this post


Link to post
Share on other sites

Could you send a sample reproducing the problem to our supoort team (java@excelsior-usa.com)? Adding System.loadLibrary to class initializer of HelloWorld does not provoke NoClassDefFoundError.

As to 64-bit, Excelsior JET creates 32-bits native executables that must run as well on 64-bits platforms.

Next year Excelsior plans to enable JET for creating also 64-bits code.  As to long primitive datatypes, we introduced a few innovative optimizations for long type to JET3.7, so even now it should be optimized rather good.

Share this post


Link to post
Share on other sites

package excelsior;

public class HelloWorld {

? ?static {

? ? ? System.loadLibrary("helloworld");

? ?}

? ?public static void main(String[] args) {

? ? ? System.out.println("hello world");

? ?}

}

After adding the static block, running the project with JET results in following console output.

JET-compiled Java program has started.

-------------------------------------

Exception in thread "main" java.lang.NoClassDefFoundError: excelsior/HelloWorld

-------------------------------------

JET-compiled Java program has exited.

It makes no difference if the library really exists or not. java.library.path is correctly set, of course. I am using JET 4.1 Evaluation.

Share this post


Link to post
Share on other sites

In JET4.1, I've really got NoClassDefFoundError , if the library does not exist (it seems to be fixed in JET 4.5). 

However, if I change the line

    System.loadLibrary("helloworld");

to

    System.loadLibrary("awt");

everything works fine.

So it seems to be that the cause of NoClassDefFoundError is java.lang.UnsatisfiedLinkError.

Please, try this (change to  System.loadLibrary("awt")). Is it ok on your side? If yes, than it is interesting anyway to get the sample where library exists and in java.library.path, but java.lang.NoClassDefFoundError is thrown anyway.

Share this post


Link to post
Share on other sites

With System.loadLibrary("awt"); it works.

Now i am not sure anymore if i recompiled my dll with the updated JNI header file. I hope this didn't cause too much trouble on your side. So, maybe you are right with the assumption that it is just a UnsatisfiedLinkError. But it shouldn't throw a NoClassDefFoundError anyway. Thanks for your help and for quick replying.

Share this post


Link to post
Share on other sites

You are right, it should not throw NoClasDefFoundError. As i said, it is already fixed in JET 4.5. However, if it is critical for you, we could prepare a hotfix for JET 4.1.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×