This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JNI, Win32, and EXE resources

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm attempting to create yet another Java service tool. After looking at the source code that comes with the Microsoft Java SDK, I found that their jexegen/jntsvc programs bind string params into a string table and raw classfile data into RT_RCDATA resources within an exe.
After some google searching, I found some good examples on how to update/read resources. However, I'm stuck when it comes to
actually instantiating the class. When I try the IBM JVM, I get to the point where I load the class but can't find the methodID for the static "main" method. When I use the Sun JVM, I don't even get that far, and my call to DefineClass returns a NULL.
Here's the source to an analog program (no EXE/DLL resource stuff, but it's pretty damn close):

(yes, it's getting to be a hack job, and yes, it's silly
to hardcode classnames in there...)
Finally, the "Hello" class it refers to is just a simple
Hello World.
Any pointers would be greatly appreciated. Thanks.
 
Corey Cole
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not to answer my own question (mostly because I don't have an answer), but I've narrowed the problem down.
I wasn't checking for exceptions after each JNI call. When I check for exceptions after each call, both the IBM and Sun JVMs
fail at the same point. I guess the IBM JVM is a little more lenient than the Sun JVM.
Anyways, it appears the issue is my creation of the ClassLoader object. I've never really played with ClassLoaders in pure code, so it's possible I'm not creating the loader object in the correct context...
 
Corey Cole
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And now the circle is complete...
I was being naive in trying to instantiate a ClassLoader
object via it's constructor. Yes, javap shows the ctor
inside the classfile, but the _real_ method you want to call is
"getSystemClassLoader".
Here's the sample code in working form:

And please, no making fun. I've been working on this
for 12 hours straight. What finally clued me in is the
Delphi(!?) source found here: http://home.pacifier.com/~mmead/jni/delphi/javadpr/javadpr_dpr.html
Regards, and thanks to the JavaRanch for letting me talk to myself.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic