I have build an executable javaFX fat jar using java 17 and javafx 18:
The JavaFXLauncher class calls the Main class which is necessary so that the executable JavaFX jar will work. It looks like this:
public class Main extends Application {
#Override
public void start(Stage stage) {
VBox vBox = new VBox();
Button okButton = new Button("OK");
okButton.setOnAction(e -> new Alert(Alert.AlertType.INFORMATION).showAndWait());
TextField searchTextField = new TextField();
vBox.getChildren().addAll(searchTextField);
ContextMenu contextMenu = new ContextMenu();
Trie<String, Integer> trie = new PatriciaTrie<>();
trie.put("calorimetru", 0);
trie.put("calamar", 0);
trie.put("abecedar", 0);
trie.put("calorie", 0);
searchTextField.setOnKeyTyped(e -> {
TextField self = (TextField) e.getSource();
if (StringUtils.isEmpty(self.getText())) {
contextMenu.hide();
return;
}
Set<String> items = trie.prefixMap(self.getText()).keySet();
if (!items.isEmpty()) {
Bounds boundsInScreen = self.localToScreen(self.getBoundsInLocal());
int height = (int) self.getHeight();
contextMenu.getItems().clear();
items.forEach(item -> contextMenu.getItems().add(new MenuItem(item)));
contextMenu.show(self, boundsInScreen.getMinX(), boundsInScreen.getMinY() + height);
}
});
Scene scene = new Scene(vBox, 500, 500, Color.WHEAT);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
I have built a native image using native-image like this:
c:\Users\adragomir\IdeaProjects\learnLambda\target>native-image.cmd -jar learnLambda-1.0.jar learn.lambda.JavaFXLauncher --no-fallback
========================================================================================================================
GraalVM Native Image: Generating 'learn.lambda.JavaFXLauncher' (executable)...
========================================================================================================================
[1/7] Initializing... (26,7s # 0,14GB)
Version info: 'GraalVM 22.1.0 Java 17 CE'
C compiler: cl.exe (microsoft, x64, 19.32.31332)
Garbage collector: Serial GC
[2/7] Performing analysis... [******] (24,5s # 0,58GB)
4.048 (75,16%) of 5.386 classes reachable
5.312 (52,92%) of 10.037 fields reachable
17.728 (44,22%) of 40.090 methods reachable
43 classes, 0 fields, and 526 methods registered for reflection
62 classes, 54 fields, and 51 methods registered for JNI access
[3/7] Building universe... (2,1s # 0,85GB)
[4/7] Parsing methods... [*] (1,7s # 1,15GB)
[5/7] Inlining methods... [****] (2,1s # 1,20GB)
[6/7] Compiling methods... [****] (18,9s # 2,68GB)
[7/7] Creating image... (3,7s # 0,60GB)
6,43MB (40,03%) for code area: 10.265 compilation units
8,43MB (52,52%) for image heap: 2.558 classes and 120.816 objects
1,20MB ( 7,45%) for other data
16,06MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 packages in code area: Top 10 object types in image heap:
743,04KB java.util 1,29MB byte[] for code metadata
376,80KB java.lang 1,14MB byte[] for general heap data
359,01KB javafx.css 1,12MB java.lang.String
346,56KB com.oracle.svm.jni 929,29KB java.lang.Class
276,85KB java.text 725,44KB byte[] for java.lang.String
238,47KB com.oracle.svm.core.reflect 403,36KB java.util.HashMap$Node
238,30KB java.util.regex 316,25KB com.oracle.svm.core.hub.DynamicHubCompanion
205,60KB java.util.concurrent 247,83KB java.util.concurrent.ConcurrentHashMap$Node
149,52KB java.math 221,23KB java.lang.String[]
148,15KB com.oracle.svm.core.code 188,09KB java.util.HashMap$Node[]
... 179 additional packages ... 1052 additional object types
(use GraalVM Dashboard to see all)
------------------------------------------------------------------------------------------------------------------------
2,6s (3,2% of total time) in 22 GCs | Peak RSS: 3,73GB | CPU load: 4,36
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
c:\Users\adragomir\IdeaProjects\learnLambda\target\learn.lambda.JavaFXLauncher.exe (executable)
c:\Users\adragomir\IdeaProjects\learnLambda\target\awt.dll (jdk_lib)
c:\Users\adragomir\IdeaProjects\learnLambda\target\java.dll (jdk_lib_shim)
c:\Users\adragomir\IdeaProjects\learnLambda\target\jvm.dll (jdk_lib_shim)
c:\Users\adragomir\IdeaProjects\learnLambda\target\learn.lambda.JavaFXLauncher.build_artifacts.txt
========================================================================================================================
Finished generating 'learn.lambda.JavaFXLauncher' in 1m 22s.
Everything seems fine but when I try to run the exe I get:
$ ./learn.lambda.JavaFXLauncher.exe
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: learn.lambda.Main
at javafx.application.Application.launch(Application.java:314)
at learn.lambda.Main.main(Main.java:67)
at learn.lambda.JavaFXLauncher.main(JavaFXLauncher.java:5)
Caused by: java.lang.ClassNotFoundException: learn.lambda.Main
at java.lang.Class.forName(DynamicHub.java:1121)
at javafx.application.Application.launch(Application.java:302)
... 2 more
I am using --no-fallback because I don't want to be dependent on a jvm, so I just want to run the exe by itself.
Do you guys have some idea on what could be wrong?
Regards,
It seems the problem is missing reflection configuration. GraalVM static analyzer cannot figure out which features are accessed reflectively, so it relies on configuration files. You can create one manually as described here, or generate with GraalVM tracing agent as described here.
I'm trying to execute the following code using JDK 17.0.1. I have ensured the JDK 17 is on the class path.
Here is the code i'm executing:
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryHandles;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
public class PanamaMain {
public static void main (String[] args) {
MemoryAddress address = MemorySegment.allocateNative(4, ResourceScope.newImplicitScope()).address();
VarHandle handle = MemoryHandles.varHandle(int.class, ByteOrder.nativeOrder());
int value = (int) handle.get(address); //This line throws the exception mentioned above.
System.out.println("Memory Value: " + value);
}
}
The cause of the exception is: java.lang.UnsatisfiedLinkError: 'java.lang.Object java.lang.invoke.VarHandle.get(java.lang.Object[])'
Exception Details
I saw some replies on a similar exception suggesting using the java.library.path system property but I got an error that the java.library.path is an invalid flag.
I would appreciate your help/tips on this issue! Thank you in advance for your time!
The VarHandle.get method is expecting a MemorySegment (not MemoryAddress) and offset in bytes within the segment. The layouts of standard C types are found in CLinker.C_XXX so you don't need to hardcode byte size of int as 4.
Assuming that your PATH is correct for launching JDK17 then this should work:
MemorySegment segment = MemorySegment.allocateNative(CLinker.C_INT, ResourceScope.newImplicitScope());
VarHandle handle = MemoryHandles.varHandle(int.class, ByteOrder.nativeOrder());
handle.set(segment, 0, 4567);
int value = (int)handle.get(segment, 0);
System.out.println("Memory Value: " + value + " = 0x"+Integer.toHexString(value));
Prints:
Memory Value: 4567 = 0x11d7
In JDK17 you can also use MemoryAccess to set or get values from allocated MemorySegment. , and could change to:
MemorySegment segment = MemorySegment.allocateNative(CLinker.C_INT, ResourceScope.newImplicitScope());
MemoryAccess.setInt(segment, -1234);
int value = MemoryAccess.getInt(segment);
System.out.println("Memory Value: " + value + " = 0x"+Integer.toHexString(value));
Prints
Memory Value: -1234 = 0xfffffb2e
Note that the API has changed, so the equivalent code in JDK18+ will be different.
I have an SAP ASE 16 server on a Windows OS.
I have enabled the java service:
sp_configure 'enable java'
Parameter Name Default Memory Used Config Value Run Value Unit Type
-------------- ----------- ----------- ------------ ------------ ------ ------
enable java 0 0 1 1 switch static
Rows affected (1) Time (0.094 s)
I have created a basic class to test the service (JDBCExamples.java):
import java.sql.*; // JDBC
public class JDBCExamples {
public static void main(String args[]){
if (args.length != 2) {
System.out.println("\n Usage: " + "name secondName \n");
return;
}
try {
String name = args[0];
String secondName = args[1].toLowerCase();
System.out.println("\n HOLA " + name + " " + secondName +" FUNCIONO!!!\n");
} catch (Exception e) {
System.out.println("\n Exception: ");
e.printStackTrace();
}
}
}
I have the class file JDBCExamples.class and I make a file JDBCExamples.jar.
When I try to install the jar file it shows the error message:
instjava -f JDBCExamples.jar -SDEFAULT -Uuser -Ppassword -Ddatabase -new
Server Message: - Msg 5702, Level 10, State 1:
ASE is terminating this process.
I don't see any in log database.
Any idea what the problem is?
Update:
I posted the same problem in https://answers.sap.com/questions/13241081/ase-is-terminating-this-process-when-trying-to-ins.html
In this post suspect the issue is caused by an ASE bug fixed in PL06:
2687973 - NTPCI__exit(1); Native Thread failed to unwind - SAP ASE http://service.sap.com/sap/support/notes/2687973
I have a trial version and I can not download a newer patch (PL06 at least but recommend PL09 as most recent)
Does anyone have this patch?
enter image description here public class GemfireTest {
public static void main(String[] args) throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException {
ServerLauncher serverLauncher = new ServerLauncher.Builder()
.setMemberName("server1")
.setServerPort(40404)
.set("start-locator", "127.0.0.1[9090]")
.build();
serverLauncher.start();
String queryString = "SELECT * FROM /gemregion";
ClientCache cache = new ClientCacheFactory().create();
QueryService queryService = cache.getQueryService();
Query query = queryService.newQuery(queryString);
SelectResults results = (SelectResults)query.execute();
int size = results.size();
System.out.println(size);
}
}
trying to run a locator and a server inside my java application getting an exception below:
Exception in thread "main" java.lang.IllegalStateException: A
connection to a distributed system already exists in this VM. It has
the following configuration: ack-severe-alert-threshold="0"
ack-wait-threshold="15" archive-disk-space-limit="0"
archive-file-size-limit="0" async-distribution-timeout="0"
async-max-queue-size="8" async-queue-timeout="60000"
bind-address="" cache-xml-file="cache.xml"
cluster-configuration-dir="" cluster-ssl-ciphers="any"
cluster-ssl-enabled="false" cluster-ssl-keystore=""
cluster-ssl-keystore-password="" cluster-ssl-keystore-type=""
cluster-ssl-protocols="any"
cluster-ssl-require-authentication="true" cluster-ssl-truststore=""
cluster-ssl-truststore-password="" conflate-events="server"
conserve-sockets="true" delta-propagation="true"
deploy-working-dir="C:\Users\Saranya\IdeaProjects\Gemfire"
disable-auto-reconnect="false" disable-tcp="false"
distributed-system-id="-1" distributed-transactions="false"
durable-client-id="" durable-client-timeout="300"
enable-cluster-configuration="true"
enable-network-partition-detection="true"
enable-time-statistics="false" enforce-unique-host="false"
gateway-ssl-ciphers="any" gateway-ssl-enabled="false"
gateway-ssl-keystore="" gateway-ssl-keystore-password=""
gateway-ssl-keystore-type="" gateway-ssl-protocols="any"
gateway-ssl-require-authentication="true" gateway-ssl-truststore=""
gateway-ssl-truststore-password="" groups=""
http-service-bind-address="" http-service-port="7070"
http-service-ssl-ciphers="any" http-service-ssl-enabled="false"
http-service-ssl-keystore="" http-service-ssl-keystore-password=""
http-service-ssl-keystore-type="" http-service-ssl-protocols="any"
http-service-ssl-require-authentication="false"
http-service-ssl-truststore=""
http-service-ssl-truststore-password="" jmx-manager="false"
jmx-manager-access-file="" jmx-manager-bind-address=""
jmx-manager-hostname-for-clients="" jmx-manager-http-port="7070"
jmx-manager-password-file="" jmx-manager-port="1099"
jmx-manager-ssl-ciphers="any" jmx-manager-ssl-enabled="false"
jmx-manager-ssl-keystore="" jmx-manager-ssl-keystore-password=""
jmx-manager-ssl-keystore-type="" jmx-manager-ssl-protocols="any"
jmx-manager-ssl-require-authentication="true"
jmx-manager-ssl-truststore="" jmx-manager-ssl-truststore-password=""
jmx-manager-start="false" jmx-manager-update-rate="2000"
load-cluster-configuration-from-dir="false" locator-wait-time="0"
locators="127.0.0.1[9090]" (wanted "") lock-memory="false"
log-disk-space-limit="0"
log-file="C:\Users\Saranya\IdeaProjects\Gemfire\server1.log"
(wanted "") log-file-size-limit="0" log-level="config" max-num-reconnect-tries="3" max-wait-time-reconnect="60000"
mcast-address="/239.192.81.1" mcast-flow-control="1048576, 0.25,
5000" mcast-port="0" mcast-recv-buffer-size="1048576"
mcast-send-buffer-size="65535" mcast-ttl="32"
member-timeout="5000" membership-port-range="[1024,65535]"
memcached-bind-address="" memcached-port="0"
memcached-protocol="ASCII" name="server1" (wanted "")
off-heap-memory-size="" redis-bind-address="" redis-password=""
redis-port="0" redundancy-zone="" remote-locators=""
remove-unresponsive-client="false" roles=""
security-client-accessor="" security-client-accessor-pp=""
security-client-auth-init="" security-client-authenticator=""
security-client-dhalgo="" security-log-file=""
security-log-level="config" security-manager=""
security-peer-auth-init="" security-peer-authenticator=""
security-peer-verifymember-timeout="1000" security-post-processor=""
security-shiro-init="" security-udp-dhalgo=""
serializable-object-filter="!" server-bind-address=""
server-ssl-ciphers="any" server-ssl-enabled="false"
server-ssl-keystore="" server-ssl-keystore-password=""
server-ssl-keystore-type="" server-ssl-protocols="any"
server-ssl-require-authentication="true" server-ssl-truststore=""
server-ssl-truststore-password="" socket-buffer-size="32768"
socket-lease-time="60000" ssl-ciphers="any" ssl-cluster-alias=""
ssl-default-alias="" ssl-enabled-components="[]"
ssl-gateway-alias="" ssl-jmx-alias="" ssl-keystore=""
ssl-keystore-password="" ssl-keystore-type="" ssl-locator-alias=""
ssl-protocols="any" ssl-require-authentication="true"
ssl-server-alias="" ssl-truststore="" ssl-truststore-password=""
ssl-truststore-type="" ssl-web-alias=""
ssl-web-require-authentication="false" start-dev-rest-api="false"
start-locator="127.0.0.1[9090]" (wanted "")*
statistic-archive-file="" statistic-sample-rate="1000"
statistic-sampling-enabled="true" tcp-port="0"
udp-fragment-size="60000" udp-recv-buffer-size="1048576"
udp-send-buffer-size="65535" use-cluster-configuration="true"
user-command-packages="" validate-serializable-objects="false"
at
org.apache.geode.distributed.internal.InternalDistributedSystem.validateSameProperties(InternalDistributedSystem.java:2959)
at
org.apache.geode.distributed.DistributedSystem.connect(DistributedSystem.java:199)
at
org.apache.geode.cache.client.ClientCacheFactory.basicCreate(ClientCacheFactory.java:243)
at
org.apache.geode.cache.client.ClientCacheFactory.create(ClientCacheFactory.java:214)
at GemfireTest.main(GemfireTest.java:61)
How to solve this exception?
The error here is pretty self explanatory: you can’t have more than one connection to a distributed system within a single JVM. In this particular case you’re starting both a server cache (ServerLauncher) and a client cache (ClientCacheFactory) within the same JVM, which is not supported.
To solve the issue, use two different applications or JVMs, one for the server and another one for the client executing the query.
Cheers.
For a university project I have to implement arules(package of R) in java. I have successfully integrated R and java using JRI. I did not understand how to get output of "inspect(Groceries[1:1])". I have tried with asString(),asString[]() but this gives me following error:
Exception in thread "main" java.lang.NullPointerException
at TestR.main(TestR.java:11)
Also, how can implement summary(Groceries) in java? How to get output of summary in String array or string?
R code:
>data(Groceries)
>inspect(Groceries[1:1])
>summary(Groceries)
Java code:
import org.rosuda.JRI.Rengine;
import org.rosuda.JRI.REXP;
public class TestR {
public static void main(String[] args){
Rengine re = new Rengine(new String[]{"--no-save"}, false, null);
re.eval("library(arules)");
re.eval("data(Groceries)");
REXP result = re.eval("inspect(Groceries[1:1])");
System.out.println(result.asString());
}
}
Appears that the inspect function in pkg:arules returns NULL. The output you see is a "side-effect". You can attempt to "capture output" but this is untested since I don't have experience with this integration across languages. Try instead.:
REXP result = re.eval("capture.output( inspect(Groceries[1:1]) )");
In an R console session you will get:
library(arules)
data("Adult")
rules <- apriori(Adult)
val <- inspect(rules[1000])
> str(val)
NULL
> val.co <- capture.output(inspect(rules[1000]))
> val.co
[1] " lhs rhs support confidence lift"
[2] "1 {education=Some-college, "
[3] " sex=Male, "
[4] " capital-loss=None} => {native-country=United-States} 0.1208181 0.9256471 1.031449"
But I haven't tested this in a non-interactive session. May need to muck with the file argument to capture.output, ... or it may not work at all.