Skip to main content

Welcome to Geoff Hayward's Weblog

Commenting on Java, JavaFX, Java EE, Joomla, and IoT.

I was having trouble working out how to remove the WAR file of a failed deployment from WildFly using the JBoss CLI. I found that I could not simply type undeploy <WAR name> to remove a failed deployment from WildFly using the JBoss CLI. However, I did find that the following command let me remove a failed deployment and it's WAR file.

/deployment=<WAR name>:remove

After running this command I checked that the failed deployment and it's WAR file had been removed by running deployment-into and then by looking in the WildFly deployment's folder on the disc. This command had successfully removed the deployment and it's WAR file.



Read

I would like to share a simple Windows Batch script that I made. The Batch script changes the WildFly's logging level quickly and easily. It is as easy as running change-logging-level.cmd --file-debug --console-error

change-logging-level.cmd

:: Name:     change-logging-level.cmd
:: Purpose:  Set's the logging level to very low or the setting given as an argument
:: Author:   geoffhayward.eu
:: Revision: August 2016 - initial version
@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET NOPAUSE=true
SET ME=%~n0
SET SCRIPT=%TEMP%\%ME%-%DATE:/=-%.txt
SET CON_LEVEL=ERROR
SET FILE_LEVEL=ERROR

:parse_args
IF NOT "%~1"=="" (
		IF "%~1"=="--all" (
		SET CON_LEVEL=ALL
		SET FILE_LEVEL=ALL
	)
	IF "%~1"=="--console-all" (
		SET CON_LEVEL=ALL
	)
	IF "%~1"=="--file-all" (
		SET FILE_LEVEL=ALL
	)
	IF "%~1"=="--config" (
		SET CON_LEVEL=CONFIG
		SET FILE_LEVEL=CONFIG
	)
	IF "%~1"=="--console-config" (
		SET CON_LEVEL=CONFIG
	)
	IF "%~1"=="--file-config" (
		SET FILE_LEVEL=CONFIG
	)
	IF "%~1"=="--debug" (
		SET CON_LEVEL=DEBUG
		SET FILE_LEVEL=DEBUG
	)
	IF "%~1"=="--console-debug" (
		SET CON_LEVEL=DEBUG
	)
	IF "%~1"=="--file-debug" (
		SET FILE_LEVEL=DEBUG
	)
	IF "%~1"=="--error" (
		SET CON_LEVEL=ERROR
		SET FILE_LEVEL=ERROR
	)
	IF "%~1"=="--console-error" (
		SET CON_LEVEL=ERROR
	)
	IF "%~1"=="--file-error" (
		SET FILE_LEVEL=ERROR
	)
	IF "%~1"=="--fatal" (
		SET CON_LEVEL=FATAL
		SET FILE_LEVEL=FATAL
	)
	IF "%~1"=="--console-fatal" (
		SET CON_LEVEL=FATAL
	)
	IF "%~1"=="--file-fatal" (
		SET FILE_LEVEL=FATAL
	)
	IF "%~1"=="--fine" (
		SET CON_LEVEL=FINE
		SET FILE_LEVEL=FINE
	)
	IF "%~1"=="--console-fine" (
		SET CON_LEVEL=FINE
	)
	IF "%~1"=="--file-fine" (
		SET FILE_LEVEL=FINE
	)
	IF "%~1"=="--finer" (
		SET CON_LEVEL=FINER
		SET FILE_LEVEL=FINER
	)
	IF "%~1"=="--console-finer" (
		SET CON_LEVEL=FINER
	)
	IF "%~1"=="--file-finer" (
		SET FILE_LEVEL=FINER
	)
	IF "%~1"=="--finest" (
		SET CON_LEVEL=FINEST
		SET FILE_LEVEL=FINEST
	)
	IF "%~1"=="--console-finest" (
		SET CON_LEVEL=FINEST
	)
	IF "%~1"=="--file-finest" (
		SET FILE_LEVEL=FINEST
	)
	IF "%~1"=="--info" (
		SET CON_LEVEL=INFO
		SET FILE_LEVEL=INFO
	)
	IF "%~1"=="--console-info" (
		SET CON_LEVEL=INFO
	)
	IF "%~1"=="--file-info" (
		SET FILE_LEVEL=INFO
	)
	IF "%~1"=="--off" (
		SET CON_LEVEL=OFF
		SET FILE_LEVEL=OFF
	)
	IF "%~1"=="--console-off" (
		SET CON_LEVEL=OFF
	)
	IF "%~1"=="--file-off" (
		SET FILE_LEVEL=OFF
	)
	IF "%~1"=="--trace" (
		SET CON_LEVEL=TRACE
		SET FILE_LEVEL=TRACE
	)
	IF "%~1"=="--console-trace" (
		SET CON_LEVEL=TRACE
	)
	IF "%~1"=="--file-trace" (
		SET FILE_LEVEL=TRACE
	)
	IF "%~1"=="--warn" (
		SET CON_LEVEL=WARN
		SET FILE_LEVEL=WARN
	)
	IF "%~1"=="--console-warn" (
		SET CON_LEVEL=WARN
	)
	IF "%~1"=="--file-warn" (
		SET FILE_LEVEL=WARN
	)
	IF "%~1"=="--warning" (
		SET CON_LEVEL=WARNING
		SET FILE_LEVEL=WARNING
	)
	IF "%~1"=="--console-warning" (
		SET CON_LEVEL=WARNING
	)
	IF "%~1"=="--file-warning" (
		SET FILE_LEVEL=WARNING
	)
	SHIFT
	GOTO :parse_args
)


ECHO batch > %SCRIPT%
ECHO /subsystem=logging/console-handler=CONSOLE:change-log-level(level=%CON_LEVEL%)>> %SCRIPT%
ECHO /subsystem=logging/periodic-rotating-file-handler=FILE:change-log-level(level=%CON_LEVEL%)>> %SCRIPT%
ECHO run-batch >> %SCRIPT%

 
CALL %JBOSS_HOME%\bin\jboss-cli.bat -c --file="%TEMP%\%ME%-%DATE:/=-%.txt"

ENDLOCAL

This version of the Batch script is designed for Windows based dev environments, with WildFly as the target dev Java EE application container. The Batch script creates a simple JBoss CLI script and then sends that script into JBoss CLI. Note %JBOSS_HOME% needs to be set as an environment variable.

Calling this 'change-logging-level.cmd' script without any arguments will set WildFly's logging level down to 'ERROR' for both the console and file logging. Supplying arguments will override the default, for example change-logging-level.cmd --fine will immediately (except long running transactions), set all logging to 'fine'.



Read

It turns out that getting EJB timer beans configured into a WildFly 9 domain cluster is quite easy. This post records how I got EJB timers working on a WildFly 9 cluster with a MySQL database as the timer bean's datasource. The domain profile I used was the 'ha' profile.

Note this post deals with EJB timer beans and assumes you already have a WildFly 9 HA domain configured with a MySQL connection.

All I had to do was configure the "timer-service" element. Here is the configuration that worked for me:

<timer-service thread-pool-name="default" default-data-store="clustered-store">
   <data-stores>
       <database-data-store name="clustered-store" datasource-jndi-name="java:/MySqlDS" database="mysql" partition="timer"/>
   </data-stores>
</timer-service>

I have read another posts about configuring a 'timer-service' with PostgreSQL that talked about updating the SQL in the 'timer-sql.properties' file. I found that MySQL just worked without the need to change the 'timer-sql.properties' file.

I created an example project to help validate the configuration. Here is the code from the example project:

MessageManager.java

@Stateless
public class MessageManager {
    
    @PersistenceContext
    private EntityManager em;
    
    public Message save(Message m){
        return em.merge(m);
    }

}

MessageTimer.java

@Stateless
public class MessageTimer {
    
    @Inject
    private MessageManager mm;
  
    @Schedule(hour = "*", minute = "*", second = "*/10", info ="Runs every 10 seconds", persistent = true)
    public void printDate() { 
        Message m = new Message();
        m.setServer(System.getProperty("server.name"));
        m.setTime(new java.util.Date().toString());
        mm.save(m);
    }
  
}

Message.java

@Entity
@Table(name="message")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Message implements Serializable {
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;
    private String time;
    private String server;
    // with getters and setters 

}

With this code the message table should get exactly one entry, from a cluster bigger than a size of one, every ten seconds. The instance that runs should be seemingly random.

Note: you need to set 'server.name' for each server in the HA group via the server's 'System Properties'.



Read

I have been struggling to configure the Java EE WildFly application server's Logging subsystem. I was finding that any changes to the configuration within domain.xml where not making any difference to what was or was not actually being logged. I finally got to the bottom of the issue.

The project, I am working on, used to run with embedded Jetty. This means some old configuration files have hung around erroneously. The old configuration files should have been deleted - but never was.

What I have learnt: WildFly's Logging subsystem uses deployment level configuration over container level configuration by default. That means old Log4j configuration files were being read by WildFly. Once I removed the old Log4j configuration files WildFly began logging as expected.

I have found out that any of the file names in the following list documented by Ritchie (2014) will be read as deployment level configuration by WildFly.

  • logging.properties
  • jboss-logging.properties
  • log4j.properties
  • log4j.xml
  • jboss-log4j.xml

Hope this helps.


Ritchie, C. 2014. WildFly Configuration, Deployment, and Administration (Second Edition), Packt Publishing, p 56.



Read

Mailing List

Responsive Media

With the ResponsiveMedia plugin for Joomla it is easy to add 3rd party content from YouTube, Vimeo, and Instagram right in to any Joomla! article.

ResponsiveMedia