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-8.1.0.Final]$ ./bin/standalone.sh ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /opt/wildfly-8.1.0.Final JAVA: /usr/lib/jvm/java-1.7.0/bin/java JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n ========================================================================= Listening for transport dt_socket at address: 8787 01:33:57,008 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final 01:33:57,508 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.2.Final 01:33:57,970 INFO [org.jboss.as] (MSC service thread 1-1) JBAS015899: WildFly 8.1.0.Final "Kenny" starting ... 01:34:56,423 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 60065ms - Started 309 of 362 services (113 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
$ /opt/wildfly-8.1.0.Final/bin/jboss-cli.sh --connect command=:shutdown {"outcome" => "success"}
All server actions can be scripted with command-line interface
Figure 91.7. Kill Standalone Server using Control-C
01:39:20,291 INFO [org.jboss.as.messaging] (MSC service thread 1-4) JBAS011601: Bound messaging object to jndi name java:jboss/DefaultJMSConnectionFactory ^C 01:39:32,666 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017532: Host default-host stopping 01:39:32,666 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 57) JBAS011605: Unbound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
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
Locate Server tab in the JavaEE Profile
Defaults are usually good enough
Start (debug and profile) option associated with server
Console output appears in IDE console window