On Jan 11, 2010, at 10:36 PM, Michael wrote:

> Hello,
> 
> I currently have a need to be able to import classes dyncamically. Now one of 
> these classes contains Java and uses Inline::Java. I've not yet successfully 
> found a way to do this.
> 
> Using an example module as follow:
> 
> package Foo;
> ...
> __END__
> 
> 
> Here is the output of attempts to use this module in a number of ways.
> 
> perl -MFoo -e '$foo = new Foo(); print $foo->jvm_version() . "\n";'
> ...
> 
> perl -e ' BEGIN { require "Foo.pm"; } $foo = new Foo; print 
> $foo->jvm_version() . "\n";'
> 

If I'm understanding this correctly, the issue is that you are skipping the 
compile phase of perl's startup when you go down the route of 'require' and 
thus your java code isn't being built and bootstrapped into the perl vm.

The first thing that comes to mind to me is that you could always ensure you 
have a sane CLASSPATH before perl executes and dynamically study specific 
classes on demand at run time. 

If you were to package your java code into proper jar files, and set your 
classpath, then you could leverage Inline::Java's study_classes method at 
runtime and dynamically load and study any class that is available to your jvm. 
This assumes that while you don't know which specific class you need, you do 
know what the universe of potential class files are.

Someone probably knows a clever way to get Inline to compile at runtime rather 
than start (compile) time, but it isn't obvious to me how to do it.

If you really need truly dynamic class loading, then the only thing I can 
personally think of off hand is to write a java library that you can load via 
Inline at start time that exposes the needed remote class loader and reflection 
capabilities. But, I have to admit, that sounds like a giant pain to implement.


--
J.


Reply via email to