JavaFX-11 with VSCode - javafx

I must be missing something obvious here... I am experimenting with VSCode (coming from Eclipse), but I am unable to get VSCode to see the JavaFX11 libraries. In the import statements, all references to JavaFX components are marked:
[Java] The import javafx cannot be resolved
In Eclipse, this is handled with a "User Library", which generates an entry in .classpath
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFX11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
While VSCode seemingly understands the rest of the .classpath from Eclipse, it does not understand this. Replacing the path attribute with the actual location on disk also does not work.
For clarity:
This question is specifically about Java 11. In earlier Java versions, JavaFX was part of the JDK. In Java 11, it has been moved to a set of external modules.
I do not want to use Maven or Gradle. I need to directly reference the modules without using a build tool.
For extra points, it would be nice if VSCode could also directly execute the JavaFX application. However, it is acceptable if I have to start the application from the command line with explicit module- and class-paths

I'm going to run the HelloFX sample for Eclipse from the OpenJFX samples.
After I open the sample with VSCode, I see the reported error: [Java] The import javafx cannot be resolved [268435846].
This obviously means that JavaFX classes are not resolved, and even if there is an entry in the .classpath file:
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFX11"/>
this library can't be resolved.
Solving JavaFX SDK
So I'm going to replace that variable with the actual jars from my local JavaFX SDK:
<classpathentry kind="lib" path="/Users/<user>/Downloads/javafx-sdk-11.0.2/lib/javafx.base.jar"/>
<classpathentry kind="lib" path="/Users/<user>/Downloads/javafx-sdk-11.0.2/lib/javafx.graphics.jar"/>
<classpathentry kind="lib" path="/Users/<user>/Downloads/javafx-sdk-11.0.2/lib/javafx.controls.jar"/>
<classpathentry kind="lib" path="/Users/<user>/Downloads/javafx-sdk-11.0.2/lib/javafx.fxml.jar"/>
After refreshing the project, I can see under JAVA DEPENDENCIES these jars.
While the error seems solved, the project still fails to build.
Solving JRE
We need to set JDK 11 for the project, so download it from here. Then open Eclipse and add it to the installed JREs. I see under Java -> Installed JREs -> Execution Environments that the name for the 11 version is JavaSE-11.
The .classpath file from the helloFX project also contains a reference to the JRE:
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/
org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JDK11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
so I'm going to replace JDK11 with JavaSE-11, and refresh the project. I can see under JAVA DEPENDENCIES that there is a reference to JRE System Library [JavaSE-11].
Solving JAVA_HOME
We need to set the java.home in VSCode.
This can be done in the settings.json from `Preferences->Settings->Workspace Settings:
{
"java.dependency.packagePresentation": "hierarchical",
"java.home":"/Users/<user>/Downloads/jdk-11.0.2.jdk/Contents/Home"
}
After modifying it, you'll get a popup with the message Java Language Server configuration changed, please restart VS Code., so restart it.
Trying it out
We can see that there are no errors, there is even a bin folder with the result of the build that automatically VSCode does.
Can we run it? If we try it out, we'll get an error:
Error: JavaFX runtime components are missing, and are required to run this application
This is the error you get when using JavaFX 11 without specifying the module-path.
Solving VM arguments
The final step consist on adding the required vm arguments.
This can be done in the launch.json file. It contains a default configuration, that we can modify adding a new entry for the vmArgs including the --module-path with the local path to the JavaFX SDK and --add-modules with the required JavaFX modules:
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - Main",
"request": "launch",
"vmArgs": "--module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib
--add-modules javafx.controls,javafx.fxml",
"mainClass": "hellofx.Main",
"projectName": "hellofx"
}
]
}
Now we have everything set.
Run the project again and it should work.
Note that I'm a first time user of VSCode, so I may have missed something obvious, and maybe some of these steps could be avoided or simplified.

launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"request": "launch",
"vmArgs": "--module-path /Volumes/Data/kits/installations/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml,javafx.graphics",
"mainClass": "application.Main",
"name": "Launch Main",
"projectName": "GooDay"
}
]
}
add this to settings json
"java.dependency.packagePresentation": "hierarchical",
"java.home":"/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home"

I think I've found a simpler answer!
Start the executable that installs your JDK
e.g.: jdk-8u201-windows-x64
Reinstall and choose to have the extra features including JavaFX installed locally.
Once the installer was done Visual Studio was able to see the files and access was no longer restricted.
If this doesn't work, I did two other things before while I was trouble-shooting (neither of these solved the problem, but one of them could've affected the result of reinstalling the JDK):
I appended a slash to the end of path to the JDK
e.g.: "C:\Program Files\Java\jdk1.8.0_201\"
Before reinstalling the JDK I connected eclipse to it and added a non-restricted access rule

Related

Tslib and QT Integration getting raw input instead of applying modules/filters on ts.conf file

I have an embedded linux system with a resistive touchscreen on /dev/input/event0 and a tslib installed. The tslib's tools such ts_calibrate and ts_tools are working perfectly with the modules/filters described in my /etc/ts.conf file.
The problem is that my QT application is not loading the library in the correct mode. It is loading tslib in raw mode, as the debug information shows.
I checked tslib's code, QT documentation and other similar questions on internet in search of any configuration that I'm missing, but apparently it's all OK.
This is my /etc/ts.conf file:
module_raw input
module pthres pmin=3975
module debounce drop_threshold=30
module variance delta=30
module dejitter delta=100
module median depth=3
module linear
This are my environment variables:
root#HMI:/application# env
SHELL=/bin/sh
RUNLEVEL=3
QWS_DISPLAY=LinuxFB:mmWidth=154.21:mmHeight=85.92
EDITOR=vi
PWD=/application
LOGNAME=root
TSLIB_CONSOLEDEVICE=none
HOME=/home/root
SSH_CONNECTION=192.168.1.30 42280 192.168.1.20 22
QT_QPA_PLATFORM=linuxfb
TSLIB_CALIBFILE=/etc/pointercal
QT_QPA_FB_TSLIB=1
TERM=xterm-256color
USER=root
SHLVL=1
TSLIB_PLUGINDIR=/usr/lib/ts
QT_DEBUG_PLUGINS=1
LD_LIBRARY_PATH=/usr/lib
XDG_RUNTIME_DIR=/var/volatile/tmp/runtime-root
PS1=\u#\h:\w\$
SSH_CLIENT=192.168.1.30 42280 22
TSLIB_TSEVENTTYPE=INPUT
TSLIB_TSDEVICE=/dev/input/event0
TSLIB_CONFFILE=/etc/ts.conf
TSLIB_FBDEVICE=/dev/fb0
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/plugins/platforms
SSH_TTY=/dev/pts/0
QT_PLUGIN_PATH=/usr/lib/plugins
QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event0
OLDPWD=/home/root
_=/usr/bin/env
And this is part of the debug output of my QT application starting it whith '''-plugin tslib''' (whole output available here):
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/plugins/generic/libqtslibplugin.so"
Found metadata in lib /usr/lib/plugins/generic/libqtslibplugin.so, metadata=
{
"IID": "org.qt-project.Qt.QGenericPluginFactoryInterface",
"MetaData": {
"Keys": [
"Tslib",
"TslibRaw"
]
},
"archreq": 0,
"className": "QTsLibPlugin",
"debug": false,
"version": 331264
}
Got keys from plugin meta data ("tslib", "tslibraw")
As you can see in "Keys" when loading the library, it says "TslibRaw". I think this is the mode in which it is loading tslib and the reason why the filters/modules described in /etc/ts.conf are not being applied.
Does someone knows how to get my QT application working whith tslib and it's modules?

error building spring webserver from corda samples

I am trying to run this spring webserver project locally as per https://github.com/corda/samples/tree/release-V4/spring-webserver using command "gradlew.bat runPartyAServer" and getting the following error "2019-08-14 18:08:20,522 main ERROR Rewrite contains an invalid element or attribute "ErrorCodeRewritePolicy"
", can you please help me fix it? PS: The corda-example nodes are already started and running. (edited)
I have already built the corda examples and they are running but spring webserver is not running but producing error
The reason for the error could be the different versions of dependencies.
You can clear the cache and do clean deploy of nodes and run them.
Once the nodes have started, start runPartyAServer again.
The exception
"ERROR Rewrite contains an invalid element or attribute "ErrorCodeRewritePolicy"" is related to version of log4j2.xml.
Most likely, the ErrorCodeRewritePolicy attribute is not present in the version of log4j2.xml file downloaded by the application.
Following is the structure of code containing ErrorCodeRewritePolicy in a log4j2.xml (see https://github.com/corda/corda/blob/master/config/dev/log4j2.xml)-
<Appenders>.....
<Rewrite name="Console-ErrorCode-Selector">
<AppenderRef ref="Console-Selector"/>
<ErrorCodeRewritePolicy/>
</Rewrite>
<Rewrite name="Console-ErrorCode-Appender-Println">
<AppenderRef ref="Console-Appender-Println"/>
<ErrorCodeRewritePolicy/>
</Rewrite>.....
Try replacing $log4j_version by "2.7" in the build.gradle.
Delete the cache and build folders and allow the gradle to download dependencies again.
Replace -
compile "org.apache.logging.log4j:log4j-web:$log4j_version"
By -
compile "org.apache.logging.log4j:log4j-web:2.7"
After alot of debugging, tracing in to the internals of Spring, I think there is a bug in the gradle.build file. I commented out these from the dependencies section:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile "junit:junit:$junit_version"
// Corda dependencies.
compile "$corda_release_group:corda-core:$corda_release_version"
compile "$corda_release_group:corda-rpc:$corda_release_version"
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") // {
// exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
// }
// compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
// compile "org.apache.logging.log4j:log4j-web:$log4j_version"
runtime "$corda_release_group:corda:$corda_release_version"
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-reflect
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.61'
}
Now my code runs without the annoying ErrorCodeRewritePolicy error messages, AND I can configure the log levels from applications.properties.

Building library with imports from another library using NX Monorepo

Here is the case. I am using Nrwl NX Monorepo. I have 2 libraries lib-a and lib-b both are publishable libraries created via NX. Now I create a MyClass.ts in lib-a. Naturally under paths in workspace/tsconfig.json paths NX creates an alias to this lib-a ("#workspace/lib-a": ["libs/lib-a/src/index.ts"]). So far so good.
Now we can use this class anywhere within the workspace/monorepo by importing it "import { MyClass } from '#workspace/lib-a';
Unfortunately we can not build lib-b which is importing MyClass. When we try to do it we get the bellow error. So question is how can we build lib-b ?
PS It seems strange that NX monorepo actually don't support such a common scenario linking 2 publishable libs.
"error TS6059: File "d:/workspace/libs/lib-a/src/index.ts" is not under 'rootDir' "d:\workspace\libs\lib-b\src" rootDir is expected to contain all source files"
Try adding
"paths": { "#workspace/*": ["dist/libs/*"] }
into your tsconfig.lib.json files. This should resolve the problem.
Try this solution. Not sure it's official, but in my case it's working well.
3 problems should be resolved:
TypeScript paths
Compiled JS paths
Working directory
First. TypeScript paths is resolved by adding "paths" into workspace/tsconfig.lib.json. NX does it automatically while lib gen. Look answer from Radovan Skendzic.
Second. Problem with compiled JS paths very good described here: Typescript paths not working in an Express project. So you need to install tsconfig-paths into your workspace:
yarn add -D tsconfig-paths
Third. Considering nx run [project]:[target] is working in workspace/ directory you should set CWD to libs/lib-b home directory - to find correct tsconfig.json
So, finally, you have the following executor (add this to your lib-b/project.json) that should work:
"targets": {
"start-dev": {
"executor": "#nrwl/workspace:run-commands",
"options": {
"commands": [
"nodemon -e ts,js --exec ts-node -r tsconfig-paths/register src/index.ts"
],
"cwd": "libs/lib-b"
}
},
...
}
Command to run:
nx run lib-b:start-dev
Don't override "baseUrl" and "paths" in any of child tsconfig!
Put all of your "paths" in tsconfig.base.ts!
Try adding lib-a as an implicit dependency of lib-b, add the line below into the libs/lib-b/project.json file and see what happens:
"implicitDependencies": ["lib-a"]
Running nx graph should show you a graph that should look something like this (do not consider the name of the libraries):
After that you should be able to build both libraries, I hope it works with you as well.

JavaFX-11 in VSCode: Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib

I have been trying to set up JavaFX-11 in Visual Studio Code.
I found this post JavaFX-11 with VSCode, which explained how to do so, and followed the steps.
However, I need to include the module-path to the JavaFX SDK by adding an entry for the vmArgs in the launch.json file:
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - Main",
"request": "launch",
"vmArgs": "--module-path C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib --add-modules javafx.controls,javafx.fxml",
"mainClass": "hellofx.Main",
"projectName": "hellofx"
}
]
}
As you can see in the vmArgs entry, is my local path to the JavaFX SDK. However, when I try to run the program I get the following error:
Error: Could not find or load main class
Files\Java\javafx-sdk-11.0.2\lib Caused by:
java.lang.ClassNotFoundException: Files\Java\javafx-sdk-11.0.2\lib
For the past hours I have trying to figure out why it doesn't work. Am I writing the arguments wrong? I saw there are .jmods files. Should I download those files? Is there any other way to specify the module path?
Is worth to mention that I am running Visual Studio Code in Windows 10, so I have to use escape sequence to use backslashes.
As you can see by the error you have posted:
Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib
it is clear that the issue is related to the space you have in Program Files.
Solutions
As a possible solution, you could move your JavaFX SDK to a folder without spaces in its path, and set your vmArgs accordingly, like:
"vmArgs": "--module-path C:\\Java\\javafx-sdk-11.0.2\\lib --add-modules javafx.controls,javafx.fxml",
While that works, if you still want to keep your current approach, you have to find a way to set the path with spaces.
Based on a similar issue, you can find that:
Paths containing spaces should be surrounded by (escaped) double quotes
So this will be the solution in your case:
"vmArgs": "--module-path \"C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib\" --add-modules javafx.controls,javafx.fxml",
Note this doesn't apply to the path added in the .classpath file with the JavaFX jars, that will be like this:
<classpathentry kind="lib" path="C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib\\javafx.base.jar"/>
Adding double quotes surrounding my environment variable in IntelliJ solved for me:
PATH_TO_FX="C:\Program Files\Java\javafx-sdk-11.0.2\lib"
** If you are having this error on Eclipse**
"Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found"
Remove the JavaFX SDK library from the build path of the project!!

gclient runhooks fails

I'm trying to build Chrome under windows, I got the chromium trunk using tortoiseSVN and I believe I got everything correctly, but when I run "gclient runhooks" I get the error: "Error: client not configured; see 'gclient config'".
Now, I know that it happens because I don't have a ".gclient" file on the same directory, but I couldn't find .gclient file anywhere in the project. I tried to create .gclient file myself but it says there's a solution missing.
I'm probably missing something, can anyone help me with that? I'm pretty stuck!
Thanks!
gclient config http://src.chromium.org/svn/trunk/src
gclient runhooks
Or make a .gclient file with the following content, which skips the huge amount of webkit layout tests
solutions = [
{ "name" : "src",
"url" : "http://src.chromium.org/svn/trunk/src",
"deps_file" : "DEPS",
"managed" : True,
"custom_deps" : {
"src/third_party/WebKit/LayoutTests": None,
"src/chrome_frame/tools/test/reference_build/chrome": None,
"src/chrome/tools/test/reference_build/chrome_mac": None,
"src/chrome/tools/test/reference_build/chrome_win": None,
"src/chrome/tools/test/reference_build/chrome_linux": None,
},
"safesync_url": "",
},
]
The above solution is out-dated. Running with the SVN repository results in:
Error:
The chromium code repository has migrated completely to git.
Your SVN-based checkout is now obsolete; you need to create a brand-new
git checkout by following these instructions:
http://www.chromium.org/developers/how-tos/get-the-code
Now you need to create a .gclient file like this
solutions = [
{
"managed": False,
"name": "src",
"url": "https://chromium.googlesource.com/chromium/src.git",
"custom_deps": {},
"deps_file": ".DEPS.git",
"safesync_url": "",
},
]
and do:
gclient sync
Chromium does not include a preconfigured .gclient file for the Chromium build and does not automatically handle Visual Studio versioning changes and default Deploy toolkit hints. After you have successfully downloaded the deploy tools and the chromium source code as provided at chromium.org perform the following in the root directory where your deploy_tools and src code is located.
NOTE : If you receive errors try to start a new command prompt session and try again.
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_VERSION = 2015
gclient config https://chromium.googlesource.com/chromium/src.git
gclient sync
gclient runhooks
cd src
ninja -C out\Debug chrome
The build will take some time gclient runhooks should generate the build folder.

Resources