getResource return null url in context of module - java-9

I am new to Java Modularity. I am using Java 9.
The program compiles without complaint. It also runs perfectly well from the "exploded module" folder, but with one exception: it throws an exception whose cause originates with the following line of code:
URL introURL = AboutPanel.class.getResource("help.html");
introURL is being assigned null.
When running the program in Eclipse, or from a jar file exported from Eclipse, the URL is populated correctly with the address of a resource file (help.html) that is in the same directory as the calling class.
Here is the command I use to run the program from the "exploded module" that is in the "out" folder:
java -p out/ -m moduleTCD/com.adonax.tanpura.TCDLaunch
The project consists of two packages that I am bundling together in a single module.
src/moduleTCD/com/adonax/tanpura
/pfaudio
The "main" class (entry point) is tanpura.TCDLaunch.
Here is the module-info.java class contents:
module moduleTCD {
exports com.adonax.tanpura;
requires java.base;
requires java.desktop;
}
The error statement, when trying to run from the command line:
java.io.IOException: invalid url
at java.desktop/javax.swing.JEditorPane.setPage(Unknown Source)
at moduleTCD/com.adonax.tanpura.documentation.AboutPanel.<init>(AboutPanel.java:28)
at moduleTCD/com.adonax.tanpura.panels.ControlPanel.initializeHelpPanel(ControlPanel.java:525)
at moduleTCD/com.adonax.tanpura.panels.ControlPanel.<init>(ControlPanel.java:163)
at moduleTCD/com.adonax.tanpura.TCDLaunch.main(TCDLaunch.java:43)
This exception is thrown in a try/catch for IOException at the point where the JEditorPane method setPage is called with null as an argument.
textArea.setPage(introURL);
At first, I didn't have an exports line in my module-info.java, but added it when I read the following from the API for Class.getResource:
Returns:
A URL object; null if no resource with this name is found, the resource cannot be located by a URL, the resource is in a package that
is not open to at least the caller module, or access to the resource
is denied by the security manager.
This raised the possibility that the package might be needed by Class in the module Java.base. The exports command there now is the broadest possible. But adding it did not change the error. I'm wondering if there is something wrong with how I did this, or if there is something else I am overlooking.

Classic error on my part. I made assumptions about the error being related to tech that is new and unfamiliar to me, rather than first verifying the obvious.
The fail was due to not realizing that the javac command did not move required resources into the target folder system.
I also verified that an "exports" statement is NOT needed in module-info in order to allow the loading of the resource.
So, in fact, this was not a java-module issue at all, just an oversight which I credit in part to a lack of chops using shell-level Java commands.
Big thank you to Alan Bateman!

Related

module java.base does not "opens java.lang.reflect" to module com.jfoenix

Before start describing how I'm getting this error, here is some important information:
It is essential the usage of the module-info.java in my project since jpackage won't work without using it.
I'm using SDK 14.0.2 (this is the minimum version that enables the usage of package)
Every comment will be appreciated; although, if you're going to comment something related to using a specific VM argument, I ask you to press ctrl+F to check if I'm already using the argument you're going to suggest -since there's a bunch of VM arguments in my build.gradle-
Ok, let's take a look about my issue:
First, focus on the VM argument below:
"--add-opens=java.base/java.lang.reflect=com.jfoenix",
If I don't use this argument, the following error pops up when the program runs:
java.lang.reflect.InaccessibleObjectException: Unable to make boolean java.lang.reflect.AccessibleObject.setAccessible0(boolean)
accessible: module java.base does not "opens java.lang.reflect" to module com.jfoenix
IMPORTANT -> This is how my view shows without using the mentioned VM argument (let's call it image 1):
https://snipboard.io/QJ5Fdc.jpg
"Ok, so why don't you just use the VM argument?"
Great question! Alright, let's add it to my VM arguments and run the program once again.
After doing so, this is how my view looks like right now (let's call it image 2): https://snipboard.io/fbhGxw.jpg
Great! This is exactly how my view should be (note that considering it worked as expected, I've got no errors this time).
So, with everything working, I can finally move on and run my jpackage gradle task. After doing so, things stop making sense, since after executing my program through a .exe (generated by jpackage) my view looks like the "image 1" view, regardless the fact that my project is working properly when I run it with the "run" gradle task.
Any thoughts on why is this happening? (My guess is that my module-info.java is the key to solve it, since every time I remove an "opens" statement, e.g.: "opens my.package.name to javafx.fxml", the program gets me almost the equal error).
Let me know whether any code samples will be needed. All assistance will be appreciated. Thanks!
edit: related GitHub issue: enter link description here
I don't know how the jpackage gradle task works, I use the jpackage tool inside the jdk via console and I used this arguments when creating the package
--java-options "--add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker=javafx.fxml --add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker.colorpicker=javafx.fxml"
In there I opened the PaintPicker from scene builder kit to javafx.fxml
As you can see I had to open two packages (they were really five but its too much to put in here) and you have to specify --add-opens for each package to open
I'm putting the code y used to package the application using jpackage
jpackage.exe
--module-path
.;D:\builds\ikonlibrowser\target\ikonlibrowser.jar;
D:\builds\ikonlibrowser\libs\icons\ikonli-antdesignicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-bootstrapicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-boxicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-bpmn-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-captainicon-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-carbonicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-codicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-coreui-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-dashicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-devicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-elusive-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-entypo-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-evaicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-feather-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-fileicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-fluentui-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-fontawesome-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-fontawesome5-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-fontelico-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-foundation-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-hawcons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-icomoon-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-ionicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-ionicons4-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-jamicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-ligaturesymbols-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-lineawesome-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-linecons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-maki-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-maki2-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-mapicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-material-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-material2-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-materialdesign-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-materialdesign2-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-medicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-metrizeicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-microns-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-ociicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-octicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-openiconic-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-paymentfont-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-prestashopicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-remixicon-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-runestroicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-simpleicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-simplelineicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-subway-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-themify-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-typicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-unicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-weathericons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-websymbols-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-whhg-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-win10-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\icons\ikonli-zondicons-pack-12.2.0.jar
D:\builds\ikonlibrowser\libs\scenebuilder-kit-16.0.0.jar;
D:\builds\ikonlibrowser\libs\jfoenix-9.0.10.jar
D:\builds\ikonlibrowser\libs\ikonli-core-12.2.0.jar;
D:\builds\ikonlibrowser\libs\ikonli-javafx-12.2.0.jar
--module jcc.app.ikonlibrowser/jcc.app.ikonlibrowser.Main
--name "Ikonli Browser" -d D:\builds\ikonlibrowser
--win-dir-chooser
--input D:\builds\ikonlibrowser\app
--vendor jCC
--app-version "1.0.0"
--java-options
"--add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker=javafx.fxml
--add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker.colorpicker=javafx.fxml
--add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker.rotator=javafx.fxml
--add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker.slider=javafx.fxml
--add-opens com.gluonhq.scenebuilder.kit/com.oracle.javafx.scenebuilder.kit.util.control.paintpicker.gradientpicker=javafx.fxml"
Of course this is only one line.
Now i'll explain it step by step:
--module-path This argument is used to specify the path for all the modules your app uses. Including the application .jar
--module This argument specifies the main class of the application. Putting first the module name and then the class full name.
--name This is to specify the app name.
-d Specifies the output path.
--win-dir-chooser Gives the option to select the installation path when installing the packaged app
--input Specifies a folder containing the external resources for your app
--vendor The vendor's name. Maybe your name
--app-version The version of your application
--java-options The jvm options
I hope it works for you, sorry for the delay.

Can I run stanza NER without downloading the language modules?

I need to run stanza ner in a platform without any access to external network. The code stanza.download('en') fails. Running without the download function, gives me an exception
Exception: Resources file not found at: \home\stanza_resources\resources.json. Try to download the model again
Is there a way to download and cache all the required modules in a resource directory and point this directory to stanza pipeline?
Thanks
It looks like both download and the Pipeline class take an argument for directory dir
So the below code works
stanza.download('en', dir='resources/', processors={ner_processor: package})
nlp_pipeline = stanza.Pipeline('en', dir='resources/', processors={ner_processor: package})

Warning thrown by script

I have written a script to update a table by passing the parameters to the script. It appears to run just fine but throws the following warnings upon execution :
*** Warning:
Problem resolving parameter "ORACLE_CLIENT_VERSION" of "/abinitio/apps30/ste-uat/CitiTech/stdenv/.project.pset":
Parameter:`ORACLE_CLIENT_VERSION' referenced before being defined in pset:`/abinitio/apps30/ste-uat/CitiTech/stdenv/.sandbox.pset'.
Can anyone tell me why these warnings are displayed or how to suppress/hide these warnings ??
I'm not sure but such a variable ("ORACLE_CLIENT_VERSION") is defined in ruby apps. For example, look here at the config.rb file.
If I were you, I would make just a search in your project for such a config file, and define the ORACLE_CLIENT_VERSION there.

Generating Pear file when using ConceptMapper Annotator

I have an UIMA project that uses the ConceptMapper Annotator. I would like to know how to set up the following:
How to specify the TokenizerDescriptionPath?
I have used the macro $main_root/descriptors/conceptMapper/primitive/OffsetTokenizer.xml, but when I was trying to install the pear file, the installer throws exceptions complaining that the file $main_root/descriptors/conceptMapper/primitive/OffsetTokenizer.xml could not be found
How to set up the value for the DictionaryFileName (A file containing the dictionary)?
In the GUI window for setting up this resource, I've filled the URL value with $main_root/data/dict/concepts.xml (my dictionary file) but at the installation time, the installer throws exceptions complaing that
Verification of uima-pipelines failed:
org.apache.uima.resource.ResourceInitializationException: Initialization of annotator class "org.apache.uima.conceptMapper.ConceptMapper" failed.
Caused by: org.apache.uima.resource.ResourceAccessException: The Resource /ConceptDetector/ConceptMapper/DictionaryFile requires parameters, none were specified.
at org.apache.uima.resource.impl.ResourceManager_impl.getResource(ResourceManager_impl.java:221)
at org.apache.uima.impl.UimaContext_ImplBase.getResourceObject(UimaContext_ImplBase.java:295)
at org.apache.uima.analysis_engine.impl.AnnotatorContext_impl.getResourceObject(AnnotatorContext_impl.java:175)
... 33 more
I had similar problems with the Concept Mapper. The way I solved the TokenizerDescriptorPath problem was to first create a PEAR file with the OffsetTokenizer as its main descriptor and the dependent classes. Then you can install this pear file locally and then set TokenizerDescriptorPath to: C:\path\to\your\pear\file\OffsetTokenizer_pear.xml. Otherwise there appears to be a CLASSPATH inheritance problem. The CLASSPATH does not seem to be passed from the ConceptMapper to the OffsetTokenizer once it is in the PEAR file. I found some great information on the GMANE listserver. user.uima.apache.org ConceptMapper Pear File Thread
I have set DictionaryFileName to file:dict/testDict.xml and this seems to work. To avoid getting a problem at save time you can add resources as a source folder.
When exporting the ConceptMapper to a PEAR file, I have both the resources and bin folder in the CLASSPATH. I have since expanded the Concept Mapper to have other annotators and it is working in a pipeline. It is all exportable to PEAR files which pass the verification step. It also works before export, locally in Eclipse.
Good Luck

Perl::WSDL. Generated methods in different directory than script

I am trying to write a script for using with op5/nagios.
What it tries to do is to connect to database an get a value there, and then send a request to a webservice and match the response from the webservice with the value from the database.
Now writing the script wasn't the problem. The problem arrises when trying to run it from OP5.
When including the interface to script I use the following syntax
use MyInterfaces::PortalServicesImplService::PortalServicesImplPort;
This works just fine when I execute the script located on the same level as "MyInterfaces".
The problem is that the script itself is located in the folder /opt/plugins/custom/SOAP where both the script and the folders generated by wsdl2perl.pl is located. However when OP5 executes the script is does so from the folder /opt/monitor.
So I tried to include the "PortalServicesImplPort" using this syntax
use lib "/opt/plugins/custom/SOAP/MyInterfaces/PortalservicesImplServices/PortalServicesImplPort
The code compiles but when trying to run it I get an error message saying
Can't locate object method "new" via package "MyInterfaces::PortalServicesImplService::PortalServicesImplPort" (perhaps you forgot to load "MyInterfaces::PortalServicesImplService::PortalServicesImplPort"?)
Am I doing something wrong when importing methods from another location or doesn't SOAP::WSDL support placing the auto generated files in a different directory from where you are executing the script?
Seems I managed to solve this myself by adding use lib "/opt/plugins/custom/SOAP

Resources