How to Fix Java.Awt.Headlessexception in Jenkins on Linux

How to fix java.awt.HeadlessException in Jenkins on Linux

These are the steps that rid me of the HeadlessException:

  1. Add the Xvnc plugin to Jenkins
  2. Install VNC: sudo apt-get update && sudo apt-get install
    vnc4server
  3. Make sure Jenkins has a shell: sudo usermod -s /bin/bash jenkins
  4. Log in as Jenkins: sudo su jenkins
  5. Enter the command vnc4server and choose a password
  6. 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.

java se

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...

jee

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



Leave a reply



Submit