Use graalvm via the standard JDK 11 - java

I have project used Nashorn Javascript engine. I'm trying to migrate to java11 and also migrate from Nashorn to Graal. I've read here that I can use graal via the standard JDK installation starting from JDK 11. Also I've read there that Graal-SDK are uploaded to Maven central, and that there is Java flag polyglot.js.nashorn-compat for easy migration. So I've used jdk11, add maven dependency to pom.xml and used java flag but when I'm trying to get engine by name "graal.js", I've got null here:
ScriptEngine engine = engineManager.getEngineByName("graal.js")
What I'm missing? How to make it work?

Here is a sample maven project that shows how to run the GraalVM JavaScript engine on JDK11 both through the scripting API and the polyglot API. Hope it helps!
https://github.com/graalvm/graal-js-jdk11-maven-demo
The gist of it is to add the necessary dependencies (graal-sdk, js, js-scriptengine, and optionally profiler and chromeinspector), Run with enabled experimental options and the JVMCI compiler (-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI) and upgrade the module path with the graal jar (--upgrade-module-path=${compiler.dir}/compiler.jar) which is also available from maven (org.graalvm.compiler:compiler).

You are missing the following dependencies:
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
</dependency>
js-scriptengine contains the ScriptEngine implementation: com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.
And the truffle-api is required (you only get the rror message if you instanciate the GraalJSEngineFactory directly:
GraalJSEngineFactory gsf = new GraalJSEngineFactory();
However there seems to be another package missing, as it does not work for me.

Related

opendj-core 6.5.0 maven dependency

On OpenDJ 2.6.4, i’m using the dependency “opendj-ldap-sdk” in order to use the
following classes:
org.forgerock.opendj.asn1.ASN1;
org.forgerock.opendj.asn1.ASN1Writer;
org.forgerock.opendj.ldap.ByteStringBuilder;
I checked that the same classes exist on Directory Services 6.5 on lib\opendj-core.jar but i cannot find the maven dependency to use it (in a context of migration from OpenDJ 2.6.4 to Directory Services 6.5).
I’ve found this dependency:
<dependency>
<groupId>org.codice.org.forgerock.opendj</groupId>
<artifactId>opendj-core</artifactId>
<version>3.0.0.ALPHA1</version>
</dependency>
but the version doesn’t match..
Where can I find the dependency?
You can unzip DS-6.5.0.zip and then add the <systemPath> element to your maven dependency. See https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies .
For a more robust mechanism, if you intend to use Directory Services 6.5 in production, then I would recommend that you contact your ForgeRock support. They will explain to you how to compile your plugin(s) against this version.

The import com.amazonaws.services.s3.AmazonS3ClientBuilder cannot be resolved

I am trying to access my s3 buckets from my java application, trying to implement this
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3-buckets.html
I've added the lib/aws-java-sdk-1.8.6.jar to my lib folder and added the dependency in my pom.xml as well.
I still get this import error
"The import com.amazonaws.services.s3.AmazonS3ClientBuilder cannot be resolved"
for "import com.amazonaws.services.s3.AmazonS3ClientBuilder;"
Whereas the imports
"import com.amazonaws.services.s3.AmazonS3;" and "import
com.amazonaws.services.s3.model.Bucket;" gave no errors.
Any help would be appreciated. I found some people trying to implement for Android ran in similar issues but not this exactly
I was having the same issue, and after some research I realized that AmazonS3ClientBuilder is not part from AWS Android SDK instead of that the class is part of AWS JAVA SDK so you have to include this on your dependencies:
implementation 'com.amazonaws:aws-java-sdk:1.11.404'
Definitely the dependency as mentioned in Amazon documentation did
not work. The path to the dependency does not exist, in Maven central repository.
"software.amazon.awssdk" % "aws-java-sdk" % "2.0.0"
The following too, did not resolve com.amazonaws.services.s3.AmazonS3ClientBuilder, though the JAR path is correct in Maven central -
"software.amazon.awssdk" % "aws-sdk-java" % "2.1.3"
I had to fallback to the following as mentioned in the previous comment.
"com.amazonaws" % "aws-java-sdk" % "1.11.465"
As I mentioned in my comment - Amazon recommends moving to V2:
The AWS SDK for Java 2.x is a major rewrite of the version 1.x code base. It’s built on top of Java 8+ and adds several frequently requested features. These include support for non-blocking I/O and the ability to plug in a different HTTP implementation at run time.
All V2 examples have been thoroughly unit tested and work (V1 code examples are old).
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/s3
For people running Spring using Maven build, the pom.xml dependency you need to import com.amazonaws.services.s3.AmazonS3ClientBuilder; into the Java class is this:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.267</version>
</dependency>
The AWS Documentation is not correct, add this to your pom.xml file:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>1.11.1005</version>
</dependency>
The AWS Documentation is not correct, add this to your pom.xml file:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.15.32</version>
</dependency>

How do you invoke schemagen in Java 11?

According to Oracle documentation the schemagen tool is removed from the JDK as part of JEP 320 (http://openjdk.java.net/jeps/320).
That JEP points to Maven artifacts that now supply the missing tools. The coordinates of the artifacts are wrong in the JEP, updated coordinates are found in an answer to this question:
Which artifacts should I use for JAXB RI in my Maven project?
What is missing however is how to invoke the tools. There are shell scripts pointed to in the JEP that are in the JAXB-RI Git repository. However those scripts remain undocumented and difficult to invoke. The build instructions in that git repo indicated it is built with a standard "mvn clean install", however that does not produce an output structure that matches the 'bin' folder used in the documentation here: https://javaee.github.io/jaxb-v2/doc/user-guide/ch04.html#tools-schemagen
Ideally I would like to run schemagen from Gradle, avoiding the shell scripts as they are not obtained from the maven dependency.
My current attempt, adapted from a working version that called the old schemagen.exe, looks like this:
(There is more in the 'real' build.gradle file to specify my application's dependencies, etc.)
configurations {
schemagenTool
}
dependencies {
schemagenTool "org.glassfish.jaxb:jaxb-jxc:${jaxbVersion}"
}
task schemaGen(type: Exec, dependsOn: [compileJava,configurations.schemaGenTool]) {
workingDir projectDir
executable 'java'
doFirst {
file('build/Schemas').mkdirs()
args '--module-path', "${configurations.schemaGenTool.asPath}",
'-m', 'jaxb.jxc/com.sun.tools.jxc.SchemaGeneratorFacade',
// Note: automatic module name is NOT com.sun.tool.jxc
// as documented
// Args to schemagen (these worked for the schemagen.exe)
'-d', 'build/Schemas',
'-classpath', "${compileJava.destinationDir}${File.pathSeparator}${configurations.compile.asPath}",
"src/main/java/path/to/my/ModelClass.java"
//println "\nschemagen: ${args.join(' ')}\n"
}
doLast {
// Above creates "build/Schemas/schema1.xsd" (despite printing a different path!)
// Rename it
def destFile = file('build/Schemas/model.xsd')
destFile.delete()
if (!file('build/Schemas/schema1.xsd').renameTo(destFile)) {
throw new GradleException("Failed to write new build/Schemas/model.xsd")
}
}
}
However, that results in an error:
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules jaxb.runtime and jaxb.core export package com.sun.xml.bind.marshaller to module relaxngDatatype
The issue seems to be known with the jaxb-*:2.3.0 version - #jaxb-v2/issues/1168. Additionally, this would be resolved with a future release as marked in the known issues of jaxb running over java-9.
You can resolve this following the comment -
Please try 2.4.0-b180725.0644 - this is JPMS modularized RI working on
JDKs with java.xml.bind module (9,10) and those without it (11-ea)
or try downloading the binary distribution from the same link.
Schemagen and xjc shell scripts are only put into binary distribution in ./bin directory.
For build tools there are plugins out there (Maven / Gradle) which does invoke schemagen and xjc APIs, providing user with simple configuration.
Your attempt to invoke com.sun.tools.jxc.SchemaGeneratorFacade manually is also correct, here is similar example for Maven. However you are probably putting 2.3.0 on module path, which has a split package problem. Putting on classpath will resolve the issue for 2.3.0. Next release of JAXB will be JPMS ready and have module descriptors declared. You can try the beta build (2.4.0-b180725.0644), here is a correct set of dependencies:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId> <!--jaxb runtime-->
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId> <!--java generation-->
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-jxc</artifactId> <!--schema generation-->
</dependency>
If trying to use the schemagen in the jaxb-ri download directly, note the JAXB_PATH in schemagen.bat is inconsistent with the mod directory in the jaxb-ri.zip file.
E.g. to use schemagen.bat:
As at now, download jaxb-ri-2.3.1.zip from https://maven.java.net/content/repositories/releases/com/sun/xml/bind/jaxb-ri/2.3.1/ (the 2.4.0-betas also had the mod/javax.activation-api.jar missing)
Use these steps to run schemagen.bat, setting JAXB_HOME as appropriate:
set JAXB_HOME=C:\Java\jaxb-ri-2.3.1
set CLASSPATH=%JAXB_HOME%/mod/relaxng-datatype.jar;%JAXB_HOME%/mod/javax.activation-api.jar
%JAXB_HOME%\bin\schemagen.bat -cp myjar1.jar;myjar2.jar -d target com.company.ClassName1 com.company.ClassName2
(This was against JDK 11)

Issues converting a project from Vaadin 7 to Vaadin 8 with plugins that are using Vaadin 7

I am converting a Vaadin 8 project to 7. When I run the app the following messages is displayed:
Widgetset 'com.vaadin.DefaultWidgetSet' does not contain an
implementation for com.vaadin.v7.ui.ProgressBar. Check the connector's
#Connect mapping, the widgetset's GWT module description file and re-
compile your widgetset.
The component it is complaining about is a vaadin plugin
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>wizards-for-vaadin</artifactId>
<version>2.0.0</version>
</dependency>
Inside "wizard-for-vaadin" plugin it is using import com.vaadin.v7.ui.ProgressBar;
How do I get "wizard-for-vaadin" plugin to play nice with Vaadin 8?
For v7 compatibility when using server-side components, annotate your UI class with:
#Widgetset(value = "com.vaadin.v7.Vaadin7WidgetSet")

Enable scripting in elasticsearch-2.2.0 using Java API

I am using elasticsearch-2.2.0 version. I need to enable scripting using JAVA API.
Basically I want to create a node using NodeBuilder and enable scripting support.
I tried setting the properties "script.inline : true" and "script.indexed : true" as below :
Settings settings = Settings.builder().put("script.inline", true).put("script.indexed", true).build();
but still it does not works.
Is there a way to enable scripting in elasticsearch-2.2.0 version using JAVA ?
This is similar to this issue and it seems that when creating a local NodeClient the lang-groovy module is not loaded by default.
So you need to add another dependency in your pom.xml
<dependency>
<groupId>org.elasticsearch.module</groupId>
<artifactId>lang-groovy</artifactId>
<version>2.2.0</version>
</dependency>

Categories

Resources