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
55 Replies
apignotti
apignotti9mo 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
Guido9mo 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
Guido9mo ago
and this is the output on the terminal window
No description
apignotti
apignotti9mo 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
Guido9mo 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
Guido9mo ago
I have attached the jar if it helps
apignotti
apignotti9mo 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
Guido9mo 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
Guido9mo ago
For reference, this is the updated app that works until the initialization window closes
apignotti
apignotti9mo 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
Guido9mo 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
Guido9mo ago
The left picture is in Cheerpj (too narrow) - the right picture in windows
No description
No description
Guido
Guido9mo ago
Is the size something that can be adjusted in the html file?
apignotti
apignotti9mo 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
apignotti9mo 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
Guido9mo 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
apignotti9mo 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
Guido9mo 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
apignotti9mo 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
Guido9mo 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
apignotti
apignotti9mo 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
Guido9mo 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
apignotti9mo 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
Guido9mo ago
Ok will check - just to verify: when you run the app you see the flatlaf look and feel in the browser?
apignotti
apignotti9mo 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
Guido9mo ago
Ok thank - so I can setup the app plus the launcher html file on my website for testing, right?
apignotti
apignotti9mo ago
Yes
Guido
Guido9mo 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
apignotti9mo 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
Guido8mo 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
apignotti8mo ago
I am not sure what you mean, there is no such thing as a "trial loader"
Guido
Guido8mo 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
apignotti8mo 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
Guido8mo 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
apignotti8mo 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
Guido8mo ago
Ok great thank you
kirillisaloser
kirillisaloser8mo 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
apignotti8mo ago
LJWGL is a native library as such it's cannot work out of the box in CheerpJ.
apignotti
apignotti8mo 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
apignotti8mo ago
Also, please don't use older questions to report new problems.
kirillisaloser
kirillisaloser8mo ago
okay
Guido
Guido6mo 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
apignotti6mo 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
Guido6mo 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
apignotti6mo 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
Guido
Guido5mo ago
Great thank you Hi Alessandro - I hope you are doing well. While testing cheerpj I came across the following effect which I couldn’t explain: I am using “cheerpjCreateDisplay(1382, 820)” to create the app window. On my standard screen it creates the app window with exactly the right pixel size 1382 X. 820. However, on the laptop screen (which has a higher dpi) it creates a screen of that is bigger than the indicated pixel size - it becomes far too big. In addition, when I move the window from the laptop screen to an external screen attached to the laptop then the app becomes really small. Do you know why? I assume there is some adjustment going on for screens of different dpi? The app runs on www.art-of-finance.net
apignotti
apignotti5mo ago
You are observing common problems caused by HiDPIs, The cheerpjCreateDisplay API reasons about "logical CSS pixels", since it created DOM elements But internally the windows will have a much higher number of pixels to match the actual monitor DPIs Without this adjustment everything would look pixelated Moving apps between monitors with different DPIs is not something that is properly supported by Java 8 as far as I can tell, so there is nothing CheerpJ can do to fix the problem. I am even unsure if the browser itself supports changing the reported DPIs in this scenario.
apignotti
apignotti5mo ago
About cheerpjCreateDisplay, what is the reason you are providing an explicit size? It's most usually better to just let sizing depend on surrounding HTML. See docs here: https://labs.leaningtech.com/cheerpj3/reference/cheerpjCreateDisplay
Leaning Technologies Developer
cheerpjCreateDisplay - CheerpJ Documentation
Display GUI elements
apignotti
apignotti5mo ago
Please avoid using old questions for ongoing discussion. The #cheerpj is more appropriate, and other members of the community might be able to help
Guido
Guido5mo ago
Ok thank you
Want results from more Discord servers?
Add your server