This question already has an answer here:
Run Java AWT/Swing GUI app in headless server
(1 answer)
Closed 7 years ago.
I have a Java Application that runs on a Windows OS, desktop machine with a nice graphical user interface. I updated, modified etc. to get it running on a Raspberry Pi 2B. It just runs about fine. However you would notice that the GUI interface is a bit slow.
On top of that I now plan to run the application on the Raspberry Pi in an optimized mode, where I don't really need the GUI. I was checking many documents about "headless mode", however, I couldn't get a proper answer to my question:
If running my standard GUI application in headless mode, does it automatically take care, i.e. neglect all methods of updating the GUI components? or what needs to be done in order to avoid Exceptions etc.?
Will it theoretically boost performance?
or shall I simply avoid feeding data into tables etc. when running in a non GUI mode?
Best Regards
No, headless mode only means the JVM is stripped of the Gui libraries. You should not use any Gui functions, they are not "stubbed out", they would fail. It emulates only a few things which can be used off-screen (mostly needed for printing or charting)
Related
This question already has answers here:
How to detect if a graphical interface is supported?
(5 answers)
Closed 8 years ago.
Update: as marked duplicate, I just want to mention, this seems like a duplicate, but the answer to the other mentioned question is not completely correct. Instead refer to the accepted answer below.
isHeadless would return unexpected true in certain cases.
Its a bit weird situation, but recently I build a very simple java application which can be run in console/terminal mode or in JavaFX UI mode.
However, then while using it on a remote computer which doesn't have any display attached. I got an error that this JavaFX UI application can't be initiated on systems without display, which is pretty obvious.
To overcome this problem, I have been looking for a robust way of detecting if the system has any display attached and it can initiate a JavaFX application, which has to be a platform independent solution, since it could be Windows or Ubuntu/Linux or Mac system.
Structure of the application:
A Main console app, which depending on input arguments executes internally a console app or UI app.
So that, if any arguments given, run in console mode or if no arguments then run in UI mode.
This is where I want to detect if there is a display available from within my main console app, which then won't even try to run the UI app if display is missing.
Any idea how can we achieve this or suggestion in a proper direction would be great.
I think you could use java.awt.GraphicsEnvironment
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
which will return an array with all the available screens. If this array is empty, there is no monitor.
Edit: About using isHeadless(), you can look at How to determine if GraphicsEnvironment exists
I have a desktop GUI program written in Java by a third party vendor. This program has a number of frames and controls on them. Now I have a requirement to start my Java program when the user clicks on a specific button on a specific frame of that Java program. Is that possible anyway? I am working on Windows 7 with JDK 7 u17.(There is a scripting language called AutoIt which provides this kind of functionality but I can not use it as it is reported as False-Positive virus by my anti-virus software, i.e. Quick Heal.) Thanks in advance.
We have 2 java applications running on MAC. One background application sends either a text or image to a clipboard, then the other application grabs that data and paste it in its application.
We have this problem when the app copies something on the clipboard, the background app won't be able to update the clipboard until it's UI becomes active.
Is there work around with this clipboard issue? This works on Windows and Linux, it seems to be a problem only on MAC.
Don't.
What you are doing is generally referred to as "interprocess communication". There are various strategies to accomplish this. One of the more 'correct' approaches, in your cotext of two Java applications, would be to use Java RMI.
Doing it in a non-standard, "hackish" manner like you are with the clipboard is more problematic...as you have discovered the hard way.
Even if you did manage to get it running, the possibilities of problems in the future are high. E.g.: Imagine a Windows update changing the behavior of the clipboard--it would break your app on Windows.
I have a Java program using AWT which I would like to run on a headless system. The display for the program does nothing other than display stats. When the program finishes, it exits. There is no user interaction on the display. The program creates an output file which I use in my build system.
Is there a way to get the Java program to run without an X11 display configured? Can I force Java to run the program without trying to display anything? I do not have access to the source code (it is just .jar file), so I can't make modifications to the source.
Any thoughts on how I could get this to work?
The underlying question here is how to run Java applications without an X server; providing a "fake" X server is only one option. In Java 1.4 and up, you can do the following:
java -Djava.awt.headless=true
This allows applications which use AWT to run on headless systems even without an X server.
Xvfb can do what you ask for. I've not used it myself, but here is a link to wikipedia: http://en.wikipedia.org/wiki/Xvfb
You can use a vncserver.
vncserver :1001
export DISPLAY=localhost:1001
java..
The added advantages is that you can actually view the gui
using vncserver 'just in case'
Could also run Xvnc in a low resolution and color depth.
As mentioned by Charles Duffy the traditional method is to tell Java to go headless.
Note that you can always mount the jar in Eclipse and use jad+jadclipse to see what it actually does, and perhaps even override a class if you need to by putting another class-file in "front" of it in the classpath.
A facility that might be relevant if the program uses Java2D is that newer Java versions use optimizations in the X11 server to render faster. This alone might be a reason to devote an X11 server attached to a high performance graphics card to your graphics processing.
I've used with great success in the past the PJA libraries, they don't seem to be maintained anymore, but then again, just just want to run...
I was able to get headless mode in OpenJFX with the command line arguments
-Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw
I'm looking for a way to know in a Java application (without JNI - it's a multi-platform application) can detect if the screen is locked.
For information... our application records time while a user is working - we want it to automatically stop recording when the screen is locked instead of the user having to do so explicitly.
I don't think there is an API for that or even a way to do it all. Parsing screenshots generated by java.awt.Robot is neither platform- nor version- or even configuration-independant, and in general, I don't think "screen is locked" is a well-enough defined concept to be used in this sense - on Linux, there can be more than just one "screen" (X server), you can switch to console terminals, you can have applications running one (or more) machines display their GUIs on another machine over the network...
I confirm there seems to be no Java API to detect a screen lock status.
Spark developer gave it a try in 2006 (like this thread shows), but without giving out any details on the specific of the implementation.
However, it is likely it involved JNI and native call to functions like WTSQuerySessionInformation (To detect if disconnected use WTSQuerySessionInformation(NULL, WTS_CURRENT_SESSION, WTSConnectState) and look for WTSDisconnected).
So, as Michael pointed out, there is no "multi-platform" universal answer (to the best of my knowledge).