Forum Stats

  • 3,723,348 Users
  • 2,244,533 Discussions


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

JNI loading Jar project from C++ class not found errors

gjijut Member Posts: 2
edited October 2018 in Java 8 Questions

Hello, using Java SE jdk1.8.0_102 on windows with Netbeans 8.2.

I have a project that has xerces.jar mail.jar activation.jar and sqljdbc4.jar as libraries. This Java project works just fine if launched from java. This is the java project.

If I try to create a C++ project that uses jni.h and loads the jvm.dll from the jdk, which loads the java project jar as a binary stream, then does a loop of Next Entry, followed by DefineClass( name, null, bytes, byteslength ) I can define most classes of the project, except five. This is the C project.

The options to load the jvm are:






the lib folder is one folder above the exe, I launch from a bat file which travels into the release folder with the exe before launching it.

Out of the five classes that dont get defined, if I hard code their defines after defining the rest of the jar, four do get defined (so its a prerequisite issue), the last one never gets defined.

The missing class is:

import javax.mail.Authenticator;import javax.mail.PasswordAuthentication;public class MyAuthenticator extends Authenticator{    String username;    String password;    public MyAuthenticator( String u , String p )    {        this.username = u;        this.password = p;    }    @Override    public PasswordAuthentication getPasswordAuthentication()    {        return new PasswordAuthentication( username, password );    }}

If I run FindClass on the C project, it finds both Authenticator and PasswordAuthentication. So it can find the classpath for javax.mail.

If I run Class.forName(javax.mail.Authenticator) in the java project it fails, the default classloader is null. If I run with true + system class loader it suceeds, but I still cant new a MyAuthenticator in regular code.

I also fail Class.forName(..sql driver) unless using the system class loader.

I also start threads within my java project main, the thread classes are defined in the project (and go past the DefineClass loop succesfully so the jvm should have them), but they still hit class not found once they are created in the java project.

Clearly I dont like JNI, too many issues, but is there a way to make this work like it works in normal mode? (with java.exe)

Sign In or Register to comment.