- 3,723,348 Users
- 2,244,533 Discussions
- 7,850,425 Comments
Forum Stats
Discussions
Categories
- 16 Data
- 362.2K Big Data Appliance
- 7 Data Science
- 2.1K Databases
- 608 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 32 Multilingual Engine
- 497 MySQL Community Space
- 7 NoSQL Database
- 7.7K Oracle Database Express Edition (XE)
- 2.8K ORDS, SODA & JSON in the Database
- 422 SQLcl
- 61 SQL Developer Data Modeler
- 185.1K SQL & PL/SQL
- 21.1K SQL Developer
- 2.4K Development
- 3 Developer Projects
- 32 Programming Languages
- 135.6K Development Tools
- 13 DevOps
- 3K QA/Testing
- 334 Java
- 10 Java Learning Subscription
- 12 Database Connectivity
- 71 Java Community Process
- 2 Java 25
- 11 Java APIs
- 141.2K Java Development Tools
- 8 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 135 Java 8 Questions
- 86.2K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 16 Java SE
- 13.8K Java Security
- 4 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 147 LiveLabs
- 34 Workshops
- 10 Software
- 4 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 4 Deutsche Oracle Community
- 16 Español
- 1.9K Japanese
- 3 Portuguese
JNI loading Jar project from C++ class not found errors

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:
-Djava.compiler=NONE
-Djava.library.path=../lib
-Djava.class.path=.;../lib/sqljdbc4.jar;../lib/activation.jar;../lib/mail.jar;../lib/xerces.jar
-verbose
-XX:+TraceClassLoading
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)