I have an application that stores configuration in a file called
config.properties. It resides in a jar file underneath all of the package
dirs, with the rest of the class files. The class that loads the config
options cannot find this resource when run through php-java-bridge.
All access is done through a central singleton called Toolbox. I wrote some
code to circumvent the Toolbox code and try to load the resource manually,
via PHP and a separate Java application. Here's what I get:
PHP
java_require("myjar.jar");
$Toolbox = new JavaClass("my.package.Toolbox");
$toolbox = $Toolbox->getInstance();
$class = $toolbox->getClass();
$r = $class->getResource("config.properties"); // null
$r = $class->getResource("/my/package/config.properties"); // null
$r = $class->getResource("my/package/config.properties"); // works, but see
below
Java
(myjar.jar in the classpath)
Toolbox toolbox = Toolbox.getInstance();
URL r;
r = toolbox.getClass().getResource("config.properties"); // works
r = toolbox.getClass().getResource("/my/package/config.properties"); //
works
r = toolbox.getClass().getResource("my/package/config.properties"); // null
myjar.jar contains
META-INF/MANIFEST.MF
my/package/config.properties
my/package/Toolbox.class
my/package/<. other .class files .>
Based on my understanding, the Java code is exhibiting the correct behavior
in terms of which resource names work and which don't. I don't think the
my/package/config.properties should work, but if it did work for both, I
could use it. Unfortunately, this is a library which will be used both by
PHP scripts and a Java app.
Any idea what I'm missing here?
Michael.
|