Problems with Cheerpj

Hello, I am trying to get my Java app running in CheerPJ - I was successful in creating a simple "Hello World" app with CheerPJ. However, my actual app (a jar file of about 4MB) doesn't work - it gets stuck at the "Graphics system is initializing" phase. I am looking for help (I am happy to share the actual .jar file if needed). Thank you Guido
apignotti
apignotti102d ago
The problem is most likely a mistake in the jars paths. Please share the HTML/JS you are using Checking the devtools console and network tab can also help
Guido
Guido102d ago
Hello this is the file I am using <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>CheerpJ test</title> <script src="https://cjrtnc.leaningtech.com/3.0rc2/cj3loader.js"></script> </head> <body> <script> (async function () { await cheerpjInit(); cheerpjCreateDisplay(800, 600); await cheerpjRunJar("/app/Wallstreet.jar"); })(); </script> </body> </html>
Guido
Guido102d ago
and this is the output on the terminal window
No description
apignotti
apignotti102d ago
The paths are correct. Check the devtools console. Please note that cheerpjRunJar should only be used when you should start the application on native using java -jar, but the JAR needs be specially designed for that to work. Otherwise you need to use cheerpjRunMain Does the application start on native with this command java -jar Wallstreet.jar
Guido
Guido98d ago
Hi Alessandro, yes, I double checked again. The application runs in a Windows terminal window with java -jar Wallstreet.jar without problems. Could there be a problem with the JDK version? I created the jar with JDK8, the jar includes some data files and icons and it includes the Flatlaf.jar library for a modern look at feel. could that be a problem?
Guido
Guido98d ago
Guido
Guido98d ago
I have attached the jar if it helps
apignotti
apignotti98d ago
The application does not work for me on Linux. I don't think this really is a platform issue (Linux vs Windows), but CheerpJ emulates a Linux environment. We cannot help further until we can run the application on Linux native. Please test using that configuration.
/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -jar Wallstreet.jar
Exception in thread "main" java.lang.NullPointerException
at Alle.codiere(Alle.java:2810)
at UserPreferences.savePref(Alle.java:6358)
at Main.<init>(Main.java:317)
at Main.main(Main.java:17908)
/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -jar Wallstreet.jar
Exception in thread "main" java.lang.NullPointerException
at Alle.codiere(Alle.java:2810)
at UserPreferences.savePref(Alle.java:6358)
at Main.<init>(Main.java:317)
at Main.main(Main.java:17908)
Guido
Guido98d ago
Thank you for your quick response - for some reason the app runs well on my linux machine, which has the following java version installed: openjdk version "11.0.18" 2023-01-17 OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.10) OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.10, mixed mode, sharing) Is there potentially an incompatibility of JDK versions? One question: the app tries to read / write from a Java preferences object called "userPrefs", e.g. userPrefs.get(), userPrefs.remove() or userPrefs.put(). Is that allowed as part of an CheerPJ app? It would be easy to omit for me in the app Hallo Alessandro - I just tested cheerpj withouth the userPrefs - seems to improve the outcome: I can now see the initialization window appearing (as in the apup). However, when the initialization window is closed and the main window should appears it seems it gets stuck again. Is it a problem to close one window and open another window? If yes, I can get rid of the initialization window easily. Thank you
Guido
Guido98d ago
Guido
Guido98d ago
For reference, this is the updated app that works until the initialization window closes
apignotti
apignotti98d ago
Both preferences and closing windows are supported, neither are the source of the problem About preferences I think that the app does not work if the preference file is not there. On your machine you have the file, but I don't The application gets into a deadlock since there is loop over SwingWorker.isDone, I'll add this a test case for the future, but we won't be able to work on this immediately. Well behaved applications should use synchronization primitives instead of polling for thread termination.
Guido
Guido98d ago
Thank you Alessandro - this is really helpful. I took out the Swingworker and now it works - really great to see this! The only issue is that the window size seems to small - is there way to adjust it? Also, it seems to ignore the flatlaf look and feel - I guess it always uses Swing standard look and feel? On the size problem - the two pics show the problem between the current size and what it would need
Guido
Guido98d ago
The left picture is in Cheerpj (too narrow) - the right picture in windows
No description
No description
Guido
Guido98d ago
Is the size something that can be adjusted in the html file?
apignotti
apignotti98d ago
The L&F throws a NPE during loading, unsure why. I see in the stack trace it mentions something about Gnome, so I wonder if it expects to be able to access configuration files that exists on native, but not on CheerpJ You can use a larger display window, you can also resize the windows with your mouse as expected
apignotti
apignotti98d ago
The L&F should load using this build: https://cjrtnc.leaningtech.com/3_20240210_363/cj3loader.js Since the window sizing issues are just a matter of changing the cheerpjCreateDisplay call I'll mark this question as solved
Guido
Guido97d ago
Great thank you - yes, that works, looks better and better. Two quick questions: 1) On the look&feel, the app has the external library "flatlaf.jar" integrated into the jar to give it a modern L&F. is there a potential problem integrating an external jar into the jar? Or are there any other options to have a more modern looking L&F? 2) When I change the html file "index" it often doesn't immediately reflect the changes when running the app. Is there some sort of "buffer" that I need to clear each time I change the html file?
apignotti
apignotti97d ago
1. CheerpJ supports multiple JARs like native Java does, there is nothing special. 2. This is not caused by CheerpJ, it's just browser caching. You might find it useful to keep the developer tools open with the "Disable cache" checkbox enabled
Guido
Guido97d ago
Thank you - for some reason the "external" library inside my jar file is not found. Is there a way to deliver the external library in a seperate file to Cheerpj? Eg the traditional way of having a lib/ folder with external jar file(s) that are used by the application?
apignotti
apignotti97d ago
Again, there is nothing cheerpj specific about this. As a matter of fact cheerpj uses the standard openjdk launcher for jars, and the behaviour is exactly the same as native. You can check the network tab of the dev tools to see which jars are loaded. Of course the external jar must be specified in the manifest, exactly like it should be with native java
Guido
Guido97d ago
Ok thank you so much - and so for bothering you with these questions - I am a bit puzzled why the local library isn't working. I tried a version where the library is in a lib/ folder (and it is recognized when I ran it with java -jar Wallstreet.jar) but it doesn't work in Cheerpj. But is is in the manifest Manifest-Version: 1.0 Ant-Version: Apache Ant 1.9.7 Created-By: 1.8.0_111-b14 (Oracle Corporation) Class-Path: lib/flatlaf-1.3.jar X-COMMENT: Main-Class will be added automatically by build Main-Class: Main For reference, this is the files I am looking at: and this file in the lib folder
Guido
Guido97d ago
Guido
Guido97d ago
apignotti
apignotti96d ago
Everything works fine for me. You can verify from the network tab that the library is loaded as expected. What is the actual problem you are observing?
Guido
Guido96d ago
Interesting - the problem I observe is that the app runs in the “old” metal look and feel instead of the flatlaf look and feel - at least in my browser
apignotti
apignotti96d ago
Please validate if the JAR is loaded from the network tab In these case the best solution is for you to deploy the app somewhere on the public internet, so that we can be sure we are looking at the same thing. There is obviously a simple mistake in the deployment, but I cannot help you effectively with just the components. I need to see the full picture.
Guido
Guido96d ago
Ok will check - just to verify: when you run the app you see the flatlaf look and feel in the browser?
apignotti
apignotti96d ago
I'll be honest, I don't know and I cannot check right now. But there is no reason why it should not work
Guido
Guido96d ago
Ok thank - so I can setup the app plus the launcher html file on my website for testing, right?
apignotti
apignotti96d ago
Yes
Guido
Guido96d ago
Thank you - I've tested the jar with external library the "flatlaf.jar" is shown in the netwok tab - when the library is nested inside the main jar then it isn't (which I think is right). I also setup the application on my website: www.art-of-finance.net - please have a look. The problem is still present: the flatlaf library is ignored (it appears in standard Metal L&F), but when I run it in Windows or Linux terminal windows, then it works well.
apignotti
apignotti96d ago
The problem is again quite obvious, you are still using the 3.0rc2 build I provided a link with an updated build days ago @Guido here
Guido
Guido75d ago
Thank you Alessandro - that works well! Apologies for missing your previous comment to use a different loader Hello Alessandro I hope you are doing well. I have been talking to your colleague Waqas and he mentioned that for private use of. cheerPJ I don’t need a licence. I just wanted to check what loader I can use ? The current one I am using is a trial loader that only works for a few moments. Thank you Guido
apignotti
apignotti75d ago
I am not sure what you mean, there is no such thing as a "trial loader"
Guido
Guido74d ago
I am using the loader you indicated above which shows a message “for personal use only etc.” - does this mean I am allowed to use it in my website ? ( as long as it is non commercial?)
apignotti
apignotti74d ago
The message explicitly says for personal and non-commercial use only, which covers your case from what you have described. I am still not sure what you meant by "only works for a few moments"
Guido
Guido74d ago
Hi Alessandro - sorry, what I meant is that sometimes a windows opens with the licensing page. I think it’s because I clicked outside the Cheerpj box
apignotti
apignotti74d ago
That should only happen when clicking on the message box at the bottom of the page. There was a bug where it would also happen when resizing a window, which was not intended. I am unsure if the build you are using was before or after this fix, so in any case please use this one: https://cjrtnc.leaningtech.com/3_20240228_437/cj3loader.js
Guido
Guido73d ago
Ok great thank you
kirillisaloser
kirillisaloser71d ago
I'm running java applet and it freezes on this and I don't know how to fix it I'm using lwjgl applet 2.1.0 ( here download lwjgl and it java applet https://sourceforge.net/projects/java-game-lib/files/Official%20Releases/LWJGL%202.1.0/)
Lightweight Java Game Library - Browse Files at SourceForge.net
The Lightweight Java Game Library (LWJGL) is a solution aimed directly at professional and amateur Java programmers alike to enable commercial…
No description
apignotti
apignotti71d ago
LJWGL is a native library as such it's cannot work out of the box in CheerpJ.
apignotti
apignotti71d ago
We have partially re-implemented it in JavaScript for our #browsercraft project, but it's far from complete. The code is here: https://github.com/leaningtech/cheerpj-natives
GitHub
GitHub - leaningtech/cheerpj-natives
Contribute to leaningtech/cheerpj-natives development by creating an account on GitHub.
apignotti
apignotti71d ago
Also, please don't use older questions to report new problems.
kirillisaloser
kirillisaloser70d ago
okay
Guido
Guido7d ago
Dear Alessandro, I hope you are doing well - I enjoying working with CheerPJ. One question: you’ve mentioned that SwingWorker currently doesn’t work in CheerPJ. I was wondering whether using a Runnable in the background instead of SwingWorker would be supported? Guido
apignotti
apignotti7d ago
Can you elaborate on what SwingWorker is and how it does not work exactly? Also, what do you man by running "in the background"? Please consider moving the discussion to the #cheerpj3 channel, this old unrelated question is not fully appropriate.
Guido
Guido7d ago
I am using SwingWorker to update a JProgressbar in a long calculation - you’ve mentioned previously that SwingWorker is currently not supported by CheerPJ?
apignotti
apignotti7d ago
Ah, now I recall. SwingWorker breaks since it spin-loops over a field without proper Java synchronization. Threading is in general fully supported in CheerpJ. So you can start a Runnable in the background sure
Want results from more Discord servers?
Add your server
More Posts
Cache Results for Faster Startup?Hello new user here. Performing initial research into potential commercial application usage. 1) AmUnknownHostException happened when the Java application connect to serverUnknownHostException happened when the Java application connect to server. The host name is the sameHTTP server returned compressed partial data. That should not happen. CheerpJ cannot run.Browser shows error "HTTP server returned compressed partial data. That should not happen. CheerpJ cAccesing the standard out and standard error stream from the Java processHow do I from javascript access the output streams from the started Java process?Any plan on adding internet access without Tailscale?Hi there ! Do you plan on adding internet access without the need to install Tailscale etc, that wour[((0 + c) | 0)] is not a function when instantiating objectHello, thank you all for developing CheerpJ, it is an impressive tool! I am playing around with tryiI'm always looking for the URL of the latest build of cj3loader.js by searching articlesI'm always looking for the URL of the latest build of cj3loader.js by searching articles, but is theDifferent behavior between extension and cj3loaderWe have a java applet that runs perfectly when using the CheerpJ browser extension, but fails to fulCan I try CheerpX?I know it's not fully ready yet, but I think it's fine for my use cases in its current staterunning java decompiler in browser, weird error(copy-pasting from #cheerpj3 since i noticed this channel existed) i'm trying to run the procyon javAccessibility of Java applicationsHi team, I noticed that apps running on CheerpJ are not accessible to people with disabilities. Thisjnlp launch verification fails with 64 bit swt librariesThe launch has below error. Java.lang.unsatisfiesLinkError: cannot load 64-bit SWT libraries on 32-bhow to debug why the jar main class is not loadingI am trying to convert old jnlp client to html format. I followed the documentation and used cheerpjTrying to get CheerpJ to actually launch a programI'm trying to get CheerpJ to run UPRandomizer in a browser, but I can't figure out how to get it to Compiling .FMX with CheerpJHow do you convert .FMX with CheerpJ compiler?Any idea on how to use wildcards for jar files with many separate jar dependencies?I've been working on some projects and one of them involves a lot of dependencies in the form of jarCan I try CheerpX for Flash?From @sergo53: > Hi! I`d like to test the CheerpX for Flash... Where can I download the package? > NFile System EmulationI'm trying to get a file system emulation POC going. https://docs.leaningtech.com/cheerp/Filesystem-Segmentation fault in linking@ap87no Like someone else in the help-archive, I'm getting a segmentation fault when I try to link t