How to fix java.awt.HeadlessException in Jenkins on Linux
These are the steps that rid me of the HeadlessException:
- Add the Xvnc plugin to Jenkins
- Install VNC:
sudo apt-get update && sudo apt-get install
vnc4server - Make sure Jenkins has a shell:
sudo usermod -s /bin/bash jenkins
- Log in as Jenkins:
sudo su jenkins
- Enter the command
vnc4server
and choose a password - Tick
Run Xvnc during build
in Jenkins' build config
java.awt.HeadlessException in docker jenkins
Quickly answer
You can not run a GUI (Graphic User Interface) java code in an operative system without user interface like servers whose objective is run applications in background mode. You need a desktop for example.
Detail answer
You can divide Java in this categories :
Java SE = Standard Edition. Commonly used for GUI or DESKTOP applications with classes like JFrame, Robot, Toolkit, etc.
Also ,contains a lot of the libraries and APIs that any Java programmer should learn (java.lang, java.io, java.math, java.net, java.util, etc...) and are used in the next category.
To run this applications, an operative system with user interface is required. If you run this applications in tomcat, in servers like jenkins, widfly, etc using ubuntu/debian,solaris,etc some parts will not work due to missing dependencies that only user interface operative systems has. For example, java.awt.Robot can move the mouse to x.y but in a shell server there is not mouse.
Java EE = Enterprise Edition. The Java platform (Enterprise Edition) is used to develop distributed systems like database access (JDBC, JPA), remote method invocation (RMI), messaging (JMS), web services, XML processing, and defines standard APIs for Enterprise JavaBeans, servlets, portlets, Java Server Pages, etc...
Currently, this category is the most used for enterprise or companies systems development: Apis rest, integrations, security, microservices, etc. Also is used to develop servers , platforms or libraries like : Tomcat, Jenkins, Pentaho, Mule ESB, Selenium, Spring, etc
Java ME = Micro Edition. This is the platform for developing applications for mobile devices. I think this is now deprecated due to Android and other tools.
How to avoid HeadlessException when running TestFX on Jenkins?
The solution was to change the node launch method on Jenkins. They were connected using SSH and changing it to connect to the master fixed the problem (ssh does not pass a GUI and connect it to the master directly does it).
Java Headless exception when trying to run an executable jar in Jenkins after the build process
Turned out that jenkins service was running under user jenkins
which had headless account and so the error
solution is to switch jenkins installation to user which has GUI access (Simple way is to deploy jenkins under tomcat container)
Related Topics
Could Not Reserve Enough Space For Object Heap
How to Use Comparator to Define a Custom Sort Order
Android Getting Value from Selected Radiobutton
Java Says Filenotfoundexception But File Exists
How to Mock Void Methods With Mockito
Best Way to Convert an Arraylist to a String
When to Use Stringbuilder in Java
How to Avoid Installing "Unlimited Strength" Jce Policy Files When Deploying an Application
Java: How to Get Input from System.Console()
Platform.Runlater and Task in Javafx
How to Use Swingworker in Java
Split String With Dot as Delimiter
Commportidentifier.Getportidentifiers with Zero Ports on Linux
Android: How to Get the Current Day of the Week (Monday, etc...) in the User's Language