Enterprise Java Development@TOPIC@
Two primary ways to run the application server
Standalone. Can be local or remote
Embedded within IDE. Shares same JVM.
Deployed applications log to an API (e.g., commons-logging, slf4j)
API bound to server logger mechanism (e.g., log4j)
Figure 91.1. Adjust Verbosity for Application
# standalone/configuration/standalone.xml
<logger category="info.ejava">
<level name="DEBUG"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
root-logger sets default versbosity to INFO
additional logger sets verbosity for info.ejava.* to DEBUG
Figure 91.2. Application Code
package info.ejava.examples.ejb.basic.ejb;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Stateless
@Remote(GreeterRemote.class)
public class GreeterEJB implements Greeter {
private static final Logger logger = LoggerFactory.getLogger(GreeterEJB.class);
@PostConstruct
public void init() {
logger.info("*** GreeterEJB ***");
}
@Override
public String sayHello(String name) throws BadRequestException {
logger.debug("sayHello({})", name);
...
}
EJB class used to create logger named after the class' fully qualified name
@PostConstruct logging at INFO level
business method logging at DEBUG level
Figure 91.3. Server Console Output
./bin/standalone.sh ... 01:17:01,990 INFO [info.ejava.examples.ejb.basic.ejb.GreeterEJB] (EJB default - 1) *** GreeterEJB ***
Console configured (by default) to only output INFO and above
Figure 91.4. Server log/server.log Output
$ tail -n 999 -f standalone/log/server.log 2014-10-01 01:17:01,990 INFO [info.ejava.examples.ejb.basic.ejb.GreeterEJB] (EJB default - 1) *** GreeterEJB *** 2014-10-01 01:17:02,009 DEBUG [info.ejava.examples.ejb.basic.ejb.GreeterEJB] (EJB default - 1) sayHello(cat inhat)
server.log will print all verbosity levels
Runs as separate process
Started/stopped by shell commands
Decoupled from IDE
Use start script (standalone.sh or standalone.bat)
Figure 91.5. Start Standalone Server at Shell
wildfly-13.0.0.Final$ ./bin/standalone.sh -c standalone.xml ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /Users/jim/apps/wildfly-13.0.0.Final JAVA: java JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true ========================================================================= 10:14:01,139 INFO [org.jboss.modules] (main) JBoss Modules version 1.8.5.Final 10:14:01,372 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.2.Final 10:14:01,379 INFO [org.jboss.threads] (main) JBoss Threads version 2.3.2.Final 10:14:01,474 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: WildFly Full 13.0.0.Final (WildFly Core 5.0.0.Final) starting ... 10:14:03,969 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 13.0.0.Final (WildFly Core 5.0.0.Final) started in 3104ms - Started 358 of 581 services (356 services are lazy, passive or on-demand)
Server can be started at the command line
Add -c profile-name.xml to run alternate profile in standalone/configuration
Server can be safely shutdown using the command line shell or Control-C
Figure 91.6. Shutdown Standalone Server using Command
wildfly-13.0.0.Final$ ./bin/jboss-cli.sh --connect command=:shutdown { "outcome" => "success", "result" => undefined }
All server actions can be scripted with command-line interface
Figure 91.7. Kill Standalone Server using Control-C
^C10:17:19,557 INFO [org.jboss.as.server] (Thread-2) WFLYSRV0236: Suspending server with no timeout. 10:17:19,558 INFO [org.jboss.as.ejb3] (Thread-2) WFLYEJB0493: EJB subsystem suspension complete 10:17:19,559 INFO [org.jboss.as.server] (Thread-2) WFLYSRV0220: Server shutdown has been requested via an OS signal ... 10:17:19,616 INFO [org.jboss.as] (MSC service thread 1-1) WFLYSRV0050: WildFly Full 13.0.0.Final (WildFly Core 5.0.0.Final) stopped in 53ms
Server can also be safely shutdown with Control-C in console window
Runs within IDE JVM
Controlled through UI clicks
Output appears in IDE panels
Provides easier access to server-side debugging and profiling
Install JBoss Tools (JBoss AS Tools) -- shown earlier
Figure 91.8. Choose New Server
Locate Server tab in the Eclipse JavaEE Profile
Right-Click in panel and select New Server
Choose most recent Wildfly configuration closest to current
Start (debug and profile) option associated with server
Console output appears in IDE console window