Referencing external JAR from JavaFX Project - javafx

I'm trying to reference a set of APIs from my JavaFX project:
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
These APIs are available in this dependency:
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0</version>
</dependency>
Therefore, I have added the jakarta.ws.rs-api in my project's module-info.java :
module com.example.javafx {
requires javafx.controls;
requires javafx.fxml;
requires org.controlsfx.controls;
//External API
requires jakarta.ws.rs-api;
opens com.example.javafx to javafx.fxml;
exports com.example.javafx;
}
However, it seems incorrect: "Module directive expected" for "jakarta.ws.rs-api".
Should I use a different format to specify the external dependency?
Thanks

You must use the module name after requires.
The dash is not a allowed character for module names, just like for package name.
You can obtain the name of a module bundled in a jar file with:
jar --describe-module --file jakarta.ws.rs-api-3.1.0.jar
which gives jakarta.ws.rs

Related

bjam fails the notfile example from the documentation?

I have seen boost-build / bjam: execute a script post install (make 'install' a dependency of executing a script) where there is a recommendation for using notfile. Then I found the https://www.boost.org/build/doc/html/bbv2/builtins/raw.html page with a basic example, where I've added the import notfile:
import notfile;
notfile echo_something : #echo ;
actions echo
{
echo "something"
}
And I've tried this snippet in a Jamroot file of a project. If I do not have the import notfile, then it fails with:
...
Jamroot:57: in modules.load
ERROR: rule "notfile" unknown in module "Jamfile</home/USER/src/myproject>".
/usr/share/boost-build/src/build/project.jam:372: in load-jamfile
/usr/share/boost-build/src/build/project.jam:64: in load
/usr/share/boost-build/src/build/project.jam:142: in project.find
/usr/share/boost-build/src/build-system.jam:618: in load
/usr/share/boost-build/src/kernel/modules.jam:295: in import
/usr/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build
/usr/share/boost-build/boost-build.jam:8: in module scope
If I have the import notfile; then it fails with:
Jamroot:56: Unescaped special character in argument notfile;
/usr/share/boost-build/src/kernel/modules.jam:258: in modules.import from module modules
error: When loading multiple modules, no specific rules or renaming is allowed
/usr/share/boost-build/src/build/project.jam:1121: in import from module Jamfile</home/USER/src/myproject>
Jamroot:62: in modules.load from module Jamfile</home/USER/src/myproject>
/usr/share/boost-build/src/build/project.jam:372: in load-jamfile from module project
/usr/share/boost-build/src/build/project.jam:64: in load from module project
/usr/share/boost-build/src/build/project.jam:142: in project.find from module project
/usr/share/boost-build/src/build-system.jam:618: in load from module build-system
/usr/share/boost-build/src/kernel/modules.jam:295: in import from module modules
/usr/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build from module
/usr/share/boost-build/boost-build.jam:8: in module scope from module
How can I get this to work?
Just noticed the "Jamroot:56: Unescaped special character in argument notfile" while writing the question which finally made sense (errors like "error: When loading multiple modules, no specific rules or renaming is allowed" are completely misleading and useless) - and I realized, I had written:
import notfile;
... that is, with semicolon directly after the word - it seems, here space is required; so with this change:
import notfile ;
... things start working again.

WebConsoleListener IllegalAccessError in JavaFX 12

I recently downloaded the latest JavaFX SDK 12 and I wish to intercept Console Messages in my JavaFX WebView.
So, I have this
WebConsoleListener.setDefaultListener((webView, message, lineNumber, sourceId) -> {
//////// I am listening for a specific console message here in my
///webview
});
but I keep getting
Caused by: java.lang.IllegalAccessError: class rumbler.launcher.ApplicationLoader (in unnamed module #0x5c4c6905) cannot access class com.sun.javafx.webkit.WebConsoleListener (in module javafx.web) because module javafx.web does not export com.sun.javafx.webkit to unnamed module #0x5c4c6905
Here is my build.gradle file
javafx {
version = "12.0.1"
modules = ['javafx.base', 'javafx.controls', 'javafx.web']
}
Here are my VM OPTIONS
--module-path "path_to_\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,javafx.web,javafx.base
.Am I missing something?
You are using private API, which is not advised.
Anyway, the error message is quite clear:
module javafx.web does not export com.sun.javafx.webkit to unnamed module #0x5c4c6905
Whenever you want to access some non-exposed package from your project (either modular on non-modular), you need to use --add-exports:
The command line option --add-exports $module/$package=$readingmodule exports $package of $module to $readingmodule. Code in $readingmodule can hence access all public types in $package but other modules can not. [source].
So in this case, the solution is straight forward:
--add-exports javafx.web/com.sun.javafx.webkit=ALL-UNNAMED \
--module-path "path_to_\javafx-sdk-11.0.2\lib" \
--add-modules javafx.web,javafx.fxml

Unable to import sumCashBy using IntelliJ IDEA

IntelliJ IDEA started highlighting errors in some of my import statements that worked previously. This is not unexpected as net.corda.finance is still in the "incubating" stage.
I am working in Java.
Corda Release: 3.3
Noticed this change on github: https://github.com/corda/corda/pull/4700
So I made what I thought are the necessary changes...
//Old
//import static net.corda.finance.utils.StateSumming.sumCashBy;
//New
import static net.corda.finance.contracts.utils.StateSumming.sumCashBy;
...but I'm still getting an error. I am sure I must be overlooking something simple.
#Kid101 put me on the right track by trying StateSumming.sumCashBy(contractState)
Once I did that IntelliJ recognized I needed to add:
net.corda:corda-finance:3.3-corda
...to the classpath. If I allowed IntelliJ to add it from the context menu the error reappeared every time gradle refreshed. So I added:
cordaCompile "$corda_release_group:corda-finance:$corda_release_version"
...to the build.gradle file under the dependencies section. No more errors with my import statement:
import net.corda.finance.utils.StateSumming;
...and no issues calling the sumCashBy method.
The change you mention is in Corda master branch, In CashTests.kt you can see how sumCashBy is imported, import net.corda.finance.contracts.utils.sumCashBy.
In corda/release-V4-branchpoint import is still net.corda.finance.utils.sumCashBy i.e. the change has not made in yet to V4.
Try to build the project again.
If using Java, try: StateSumming.sumCashBy(contractState)
You should import a dependency package.
You add below to build.gradle and refresh your IntelliJ project.
dependencies {
....
cordaCompile "$corda_core_release_group:corda-finance-contracts:$corda_core_release_version"
...

Servlet class is not a javax.servlet.Servlet while deploying a bundle in felix jetty

I am trying to deploy an OSGI bundle in felix jetty. BootStrap is my class which extends HttpServlet.
I am getting the below Exception at deployment stage :
ins.server.servlet.HttpServlet30Dispatcher is not assignable from javax.servlet.http.HttpServlet
2018-07-11T07:46:55,044 WARN sure-rest-neo [] web-reactor - unavailable
javax.servlet.UnavailableException: Servlet class com.nokia.mdf.sure.neo.utils.Bootstrap is not a javax.servlet.Servlet
at org.eclipse.jetty.servlet.ServletHolder.checkServletType(ServletHolder.java:519) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:379) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-util-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:874) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404) ~[jetty-webapp-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366) ~[jetty-webapp-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778) ~[jetty-server-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520) ~[jetty-webapp-9.3.10.v20160621.jar:9.3.10.v20160621]
I have embedded all dependencies including the transitive ones. How to resolve this, which I assume is due to jar conflict ?
The problem is exactly with embedding dependencies. When you embed the javax.servlet package then your bundle will use the embedded class while jetty will use the class available from an exported package. So while these classes are named the same there are different instances in the classloaders which leads to exactly this kind of error.
To generally solve this you make sure that ideally only one bundle exports each package and all bundles that need it import the package. So the easiest solution is to not embed dependencies.
If that does not work for you then you can try to import and export the javax.servlet package in your bundle. This allows the OSGi environment to decide which package it will actually wire and avoid having the same class names with different instances in bundles.

RFT- What JAR file do i need to use 'import javax.xml.parsers.DocumentBuilder'

On my scenario, I'm trying to retrieve the information of an applicant from an XML file. I'm trying to retrieve the data of certain tags within the xml file and insert the string to an CSV file to use it as the datapool.
Im trying to use the following Imports
import javax.xml.parsers.DocumentBuilder;
import javaxxml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
When i try to use the above import classes i get an error (The import cannot be resolved)
I have added the JAR file JDOM to my project , but that didn't work.
I was using "java" instead of "javax" i'm no longer getting the error
findjar.com tells me it's in rt.jar (as of Java 6)
rt.jar contains all the RunTime classes that comprise the Java SE
platform’s core API’s. In simple terms this is the jar which contains
classes like java.lang.String, java.io package etc.
Could be Java SE or Apache Xerces or AWT
They all have the same class within same package.

Resources