Kohei Nozaki's blog 

Entries tagged [wildfly]

Install Apache Roller5


Posted on Thursday May 15, 2014 at 11:54AM in Technology


Environment

  • WildFly 8.1.0.CR1
  • Oracle JDK8u5
  • PostgreSQL 9.2.4
  • roller-weblogger-5.0.3-for-javaee.tar.gz
  • OS X 10.9.2

Preconditions

  • Ensure appropriate JDBC driver is installed to WildFly.

Create a database for Roller

postgres=# create database roller owner kyle encoding 'UTF8' TEMPLATE template0;
CREATE DATABASE
postgres=# 

Create a DataSource

  • Using jboss-cli.
data-source add \
 --name=RollerDS \
 --driver-name=postgresql \
 --connection-url=jdbc:postgresql://localhost:5432/roller \
 --jndi-name=java:jboss/jdbc/RollerDS \
 --user-name=postgres \
 --password=postgres \
 --jta=false \
 --use-java-context=false

Create the WAR with modified persistence.xml

Why need this?

  • Roller5 uses JPA, and defines its JNDI datasource name in persistence.xml as “jdbc/rollerdb”
  • But, WildFly doesn't allow such JNDI name. datasource creation will fail like this:
JBAS010471: Jndi name have to start with java:/ or java:jboss/
  • Also, Roller5 installation guide mentioned about installation procedure for JBoss6, but it seems obsoleted.
  • If possible, I recommend you to use other application servers like Tomcat or GlassFish at the moment because it needs many additional procedures to getting work with WildFly.

Extract the WAR

kyle-no-MacBook:tmp kyle$ pwd
/tmp
kyle-no-MacBook:tmp kyle$ mkdir roller
kyle-no-MacBook:tmp kyle$ cd roller
kyle-no-MacBook:roller kyle$ mkdir war
kyle-no-MacBook:roller kyle$ cd war
kyle-no-MacBook:war kyle$ jar xvf ~/Downloads/tmp/roller-weblogger-5.0.3-javaee/webapp/roller-5.0.3-javaee.war 

Extract roller-planet-business-5.0.3.jar

kyle-no-MacBook:war kyle$ cd ../
kyle-no-MacBook:roller kyle$ mkdir planet
kyle-no-MacBook:roller kyle$ cd planet
kyle-no-MacBook:planet kyle$ jar xvf ../war/WEB-INF/lib/roller-planet-business-5.0.3.jar

Modify persistence.xml inside roller-planet-business-5.0.3.jar

kyle-no-MacBook:planet kyle$ sed -i -e "s/jdbc\/rollerdb/java:jboss\/jdbc\/RollerDS/" META-INF/persistence.xml
  • Now, persistence.xml like this:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name ="PlanetPU" transaction-type = "RESOURCE_LOCAL"> 
        <non-jta-data-source>java:jboss/jdbc/RollerDS</non-jta-data-source>
        <mapping-file>org/apache/roller/planet/pojos/RuntimeConfigProperty.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/planet/pojos/Planet.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/planet/pojos/PlanetGroup.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/planet/pojos/Subscription.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/planet/pojos/SubscriptionEntry.orm.xml</mapping-file> 
    </persistence-unit>
</persistence>

Extract roller-weblogger-business-5.0.3.jar

kyle-no-MacBook:planet kyle$ cd ..
kyle-no-MacBook:roller kyle$ mkdir weblogger
kyle-no-MacBook:roller kyle$ cd weblogger/
kyle-no-MacBook:weblogger kyle$ jar xvf ../war/WEB-INF/lib/roller-weblogger-business-5.0.3.jar 

Modify persistence.xml inside roller-weblogger-business-5.0.3.jar

  • Replace JNDI name
kyle-no-MacBook:weblogger kyle$ sed -i -e "s/jdbc\/rollerdb/java:jboss\/jdbc\/RollerDS/" META-INF/persistence.xml
  • Add declaration of an additional property which enables bind EntityManagerFactory to JNDI. detail information: [3]
        <properties>
           <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/jpa/RollerEMF" />
        </properties>
  • Also, trimming is needed.
kyle-no-MacBook:weblogger kyle$ sed -i -e "s/orm\.xml *</orm\.xml</g" META-INF/persistence.xml
  • If skip this, WildFly will complains like this and deployment fails:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: RollerPU] Unable to resolve named mapping-file [org/apache/roller/weblogger/pojos/TaskLock.orm.xml                ]
  • Now, persistence.xml is:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name ="RollerPU" transaction-type="RESOURCE_LOCAL"> 
        <non-jta-data-source>java:jboss/jdbc/RollerDS</non-jta-data-source>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogBookmark.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogEntryComment.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogEntryAttribute.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogBookmarkFolder.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogHitCount.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/PingQueueEntry.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/PingTarget.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogReferrer.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/UserRole.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/RuntimeConfigProperty.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/TaskLock.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/User.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogCategory.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogEntry.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogEntryTagAggregate.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogEntryTag.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogTemplate.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/ObjectPermission.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/WeblogPermission.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/Weblog.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/UserAttribute.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/OAuthConsumerRecord.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/OAuthAccessorRecord.orm.xml</mapping-file>
        <mapping-file>org/apache/roller/weblogger/pojos/MediaFile.orm.xml</mapping-file>    
        <mapping-file>org/apache/roller/weblogger/pojos/MediaFileTag.orm.xml</mapping-file> 
        <mapping-file>org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml</mapping-file>
        <class>org.apache.roller.weblogger.pojos.AutoPing</class>
        <properties>
           <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/jpa/RollerEMF" />
        </properties>
    </persistence-unit>  
</persistence>

Create jars

kyle-no-MacBook:roller kyle$ cd planet/
kyle-no-MacBook:planet kyle$ jar cvf ../roller-planet-business-5.0.3-for-wildfly.jar .
kyle-no-MacBook:planet kyle$ cd ../weblogger/
kyle-no-MacBook:weblogger kyle$ jar cvf ../roller-weblogger-business-5.0.3-for-wildfly.jar .

Put jars into WEB-INF

kyle-no-MacBook:roller kyle$ pwd
/tmp/roller
kyle-no-MacBook:roller kyle$ cp roller-planet-business-5.0.3-for-wildfly.jar war/WEB-INF/lib/roller-planet-business-5.0.3.jar 
kyle-no-MacBook:roller kyle$ cp roller-weblogger-business-5.0.3-for-wildfly.jar war/WEB-INF/lib/roller-weblogger-business-5.0.3.jar 

Put jboss-web.xml into WEB-INF

  • Path:
kyle-no-MacBook:WEB-INF kyle$ pwd
/tmp/roller/war/WEB-INF
  • It goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <resource-ref>
        <res-ref-name>jdbc/rollerdb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:jboss/jdbc/RollerDS</jndi-name>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jpa/rolleremf</res-ref-name>
        <res-type>javax.persistence.EntityManagerFactory</res-type>
        <jndi-name>java:jboss/jpa/RollerEMF</jndi-name>
    </resource-ref>
    <resource-ref>
        <res-ref-name>mail/Session</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <jndi-name>java:/mail/myMail</jndi-name>
    </resource-ref>
</jboss-web>

Put roller-custom.properties into WEB-INF/classes

  • Path:
kyle-no-MacBook:classes kyle$ pwd
/tmp/roller/war/WEB-INF/classes
  • It goes like this:
jpa.configurationType=jndi
jpa.emf.jndi.name=jpa/rolleremf
installation.type=auto
mediafiles.storage.dir=/Users/kyle/tmp/rollerdata/mediafiles
search.index.dir=/Users/kyle/tmp/rollerdata/searchindex
log4j.appender.roller.File=/Users/kyle/tmp/rollerdata/roller.log
database.jndi.name=java:jboss/jdbc/RollerDS

Create the WAR

kyle-no-MacBook:roller kyle$ pwd
/tmp/roller
kyle-no-MacBook:roller kyle$ cd war
kyle-no-MacBook:war kyle$ jar cvf ../roller.war .

Deploy

cp roller.war ~/apps/wildfly/standalone/deployments
  • It goes like this:
2014-05-15 14:25:17,648 TRACE [org.hibernate.type.TypeFactory] (ServerService Thread Pool -- 311) Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@5fcdf39a
2014-05-15 14:25:17,842 TRACE [org.hibernate.type.TypeFactory] (ServerService Thread Pool -- 310) Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@745bcb72
2014-05-15 14:25:18,626 INFO  [org.apache.roller.weblogger.business.DatabaseProvider] (MSC service thread 1-3) SUCCESS: Got parameters. Using configuration type JNDI_NAME
2014-05-15 14:25:18,626 INFO  [org.apache.roller.weblogger.business.DatabaseProvider] (MSC service thread 1-3) -- Using JNDI datasource name: java:jboss/jdbc/RollerDS
2014-05-15 14:25:18,627 INFO  [org.apache.roller.weblogger.business.DatabaseProvider] (MSC service thread 1-3) SUCCESS: located JNDI DataSource [java:jboss/jdbc/RollerDS]
2014-05-15 14:25:19,998 INFO  [org.apache.roller.weblogger.ui.core.RollerContext] (MSC service thread 1-3) 
--------------------------------------------------------------
Roller Weblogger startup INCOMPLETE, user interaction required
--------------------------------------------------------------
2014-05-15 14:25:19,999 INFO  [org.apache.roller.weblogger.ui.core.RollerContext] (MSC service thread 1-3) Remember Me enabled: true
2014-05-15 14:25:20,000 INFO  [org.apache.roller.weblogger.ui.core.RollerContext] (MSC service thread 1-3) Password Encryption Algorithm set to 'SHA'
2014-05-15 14:25:20,000 INFO  [org.apache.roller.weblogger.ui.core.RollerContext] (MSC service thread 1-3) Initializing Velocity
2014-05-15 14:25:20,136 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.SearchServlet] (MSC service thread 1-3) Initializing SearchServlet
2014-05-15 14:25:20,136 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.FeedServlet] (MSC service thread 1-3) Initializing FeedServlet
2014-05-15 14:25:20,137 INFO  [org.apache.roller.weblogger.ui.rendering.util.cache.WeblogFeedCache] (MSC service thread 1-3) {size=200, id=cache.weblogfeed, timeout=3600, enabled=true}
2014-05-15 14:25:20,139 INFO  [org.apache.roller.weblogger.util.cache.CacheManager] (MSC service thread 1-3) Cache Manager Initialized.
2014-05-15 14:25:20,139 INFO  [org.apache.roller.weblogger.util.cache.CacheManager] (MSC service thread 1-3) Cache Factory = org.apache.roller.weblogger.util.cache.ExpiringLRUCacheFactoryImpl
2014-05-15 14:25:20,142 INFO  [org.apache.roller.weblogger.ui.rendering.util.cache.SiteWideCache] (MSC service thread 1-3) {size=50, id=cache.sitewide, enabled=true, timeout=1800}
2014-05-15 14:25:20,142 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.ResourceServlet] (MSC service thread 1-3) Initializing ResourceServlet
2014-05-15 14:25:20,142 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.PageServlet] (MSC service thread 1-3) Initializing PageServlet
2014-05-15 14:25:20,143 INFO  [org.apache.roller.weblogger.ui.rendering.util.cache.WeblogPageCache] (MSC service thread 1-3) {size=400, id=cache.weblogpage, enabled=true, timeout=3600}
2014-05-15 14:25:20,143 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.PageServlet] (MSC service thread 1-3) Referrer processing enabled = true
2014-05-15 14:25:20,143 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.MediaResourceServlet] (MSC service thread 1-3) Initializing ResourceServlet
2014-05-15 14:25:20,144 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.CommentServlet] (MSC service thread 1-3) Initializing CommentServlet
2014-05-15 14:25:20,153 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured CommentValidator: ブラックリストコメント排除 / org.apache.roller.weblogger.ui.rendering.plugins.comments.BlacklistCommentValidator
2014-05-15 14:25:20,154 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured CommentValidator: 多すぎるリンクが入ったコメントバリケーダ / org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator
2014-05-15 14:25:20,154 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured CommentValidator: コメントバリケーダ / org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessSizeCommentValidator
2014-05-15 14:25:20,155 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured 3 CommentValidators
2014-05-15 14:25:20,155 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.CommentServlet] (MSC service thread 1-3) Comment Throttling DISABLED
2014-05-15 14:25:20,155 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.PlanetFeedServlet] (MSC service thread 1-3) Initializing PlanetRssServlet
2014-05-15 14:25:20,156 INFO  [org.apache.roller.weblogger.ui.rendering.util.cache.PlanetCache] (MSC service thread 1-3) Planet cache = {size=10, id=cache.planet, timeout=1800, enabled=true}
2014-05-15 14:25:20,156 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.RSDServlet] (MSC service thread 1-3) Initializing RSDServlet
2014-05-15 14:25:20,157 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured CommentValidator: ブラックリストコメント排除 / org.apache.roller.weblogger.ui.rendering.plugins.comments.BlacklistCommentValidator
2014-05-15 14:25:20,157 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured CommentValidator: 多すぎるリンクが入ったコメントバリケーダ / org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator
2014-05-15 14:25:20,158 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured CommentValidator: コメントバリケーダ / org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessSizeCommentValidator
2014-05-15 14:25:20,158 INFO  [org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentValidationManager] (MSC service thread 1-3) Configured 3 CommentValidators
2014-05-15 14:25:20,159 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.PreviewServlet] (MSC service thread 1-3) Initializing PreviewServlet
2014-05-15 14:25:20,160 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.PreviewThemeImageServlet] (MSC service thread 1-3) Initializing PreviewThemeImageServlet
2014-05-15 14:25:20,160 INFO  [org.apache.roller.weblogger.ui.rendering.servlets.PreviewResourceServlet] (MSC service thread 1-3) Initializing PreviewResourceServlet

Access to the page

  • Finally the top page is shown!

  • The button triggers schema creation.

roller=# \d
                  List of relations
 Schema |           Name           | Type  |  Owner   
--------+--------------------------+-------+----------
 public | autoping                 | table | postgres
 public | bookmark                 | table | postgres
 public | entryattribute           | table | postgres
...
  • Finally I saw the welcome page!

Don't forget: Reset the installation.type flag

  • Roller installation guide said:

Now that you're done with the installation you should turn off Roller's auto-installation system. Edit your roller-custom.properties file and set installation.type=manual. Then restart your server or Roller so that it accepts the new setting.

  • So, you need to edit the roller-custom.properties and re-deploy.

References

  1. Why not java:global/datasources? | Community
  2. Roller 5 and JBoss 6
  3. Binding EntityManagerFactory/EntityManager to JNDI
  4. Une tasse de cafe
  5. Apache Roller: TJシステム設計


How to define JVM parameters


Posted on Friday Mar 07, 2014 at 08:09AM in Technology


Environment

  • WildFly 8.0.0.Final
  • JBoss Tools (Kepler) 4.1.1.Final
  • Eclipse Kepler SR1
  • Oracle JDK7u51
  • OS X 10.9.2

Test Servlet

  • This time we're going to test it with enabling of assertion.
@WebServlet("/")
public class AssertServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        assert false : "test";
    }
}

Configure standalone.conf for launching through standalone.sh

  • Add this statement to $WILDFLY_HOME/bin/standalone.conf
JAVA_OPTS=$JAVA_OPTS -ea
  • This can be done on unix systems like this:
echo "JAVA_OPTS=\"\$JAVA_OPTS -ea\"" >> standalone.conf
  • Now the Servlet throws Assertion Error when we launch WildFly through standalone.sh:
09:05:00,614 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /assert/: java.lang.AssertionError: test
    at assert0.AssertServlet.doGet(AssertServlet.java:16) [classes:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
...
  • But it won't work with WildFly instances that launched by Eclipse.

Configuring Eclipse

  1. Open Servers view and double-click WildFly instance

  2. Click “Open launch configuration”

  3. Add “-ea” to “VM arguments:” - OK

wildfly-maven-plugin

  • Like this:
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <version>1.0.1.Final</version>

                        <configuration>
                            <jboss-home>${wildfly.home}</jboss-home>
                            <modules-path>${wildfly.home}/modules</modules-path>
                            <jvm-args>-ea -Xms64m -Xmx512m -XX:MaxPermSize=256m
                                -Djava.net.preferIPv4Stack=true
                                -Djboss.server.base.dir=${wildfly.home}/standalone
                                -Djboss.socket.binding.port-offset=${wildfly.port.offset}</jvm-args>
                            <port>${wildfly.port.mgmt}</port>
                        </configuration>
...

Assertion notes

Eclipse

  • We can enable assertion for every JUnit run configuration which will newly create.

  • This won't make assertions enable for already created run configurations.

Maven Surefire Plugin

  • “By default, Surefire enables JVM assertions for the execution of your test cases. To disable the assertions, set this flag to “false”[3].

References

  1. Configure JVM settings for Standalone Mode from… | Community
  2. How to enable Assertions in eclipse (IDEs and Version Control forum at JavaRanch)
  3. Maven Surefire Plugin - surefire:test


Profiling with VisualVM


Posted on Thursday Mar 06, 2014 at 05:04PM in Technology


Environment

Local

  • VisualVM 1.7.0_51 (Build 1352-130117); platform 20130117-unknown-revn
  • WildFly 8.0.0.Final
  • Oracle JDK7u51
  • OS X 10.9.2

Remote profiling target

  • WildFly 8.0.0.Final
  • Oracle JDK7u45
  • OS X 10.9.1

Profiling local instances

  • We don't need any special operation to profiling with local instances.
  • After just launch VisualVM, we can see local instances.

Profiling Remote instances

Create a management user in the target instance

kyle-no-MacBook:bin kyle$ pwd
/Users/kyle/apps/wildfly-8.0.0.Final/bin
kyle-no-MacBook:bin kyle$ ./add-user.sh kyle ***
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Added user 'kyle' to file '/Users/kyle/apps/wildfly-8.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'kyle' to file '/Users/kyle/apps/wildfly-8.0.0.Final/domain/configuration/mgmt-users.properties'
kyle-no-MacBook:bin kyle$ 

Define a system property in the target instance to accept connection from remote host

  • CAUTION: this makes management port to accept connections from everyone.
/system-property=jboss.bind.address.management:add(value=0.0.0.0)

Launch VisualVM

  • We have to specify an additional jar on startup option like this:
jvisualvm --cp:a /Users/kyle/apps/wildfly-8.0.0.Final/bin/client/jboss-cli-client.jar
  • If it doesn't work, try “-cp:a” instead

Add and connect to target

  1. Right-click “Remote” - “Add a remote host”

  2. Enter hostname - OK

  3. Right-click hostname - add a JMX connection

  4. Enter connection url, username and password that created in above step - OK NOTICE: Usually, WildFly's management port is 9990. I customized it as 49990 for my environment.

  5. Double-click a icon which appeared with JMX icon. now we can do profiling with remote WildFly instance.

service:jmx:http-remoting-jmx://[HOSTNAME]:9990

References

  1. Connecting VisualVM with a remote JBoss AS 7 / EAP6 JVM process | akquinet-blog
  2. [AS7-4695] Server does not start with sun jmx enabled - JBoss Issue Tracker
  3. Using jconsole to connect to JMX on AS7 | Community
  4. adding alternative jmx connectivity (i.e. JBoss 7) | Oracle Community
  5. JMX subsystem configuration - WildFly 8 - Project Documentation Editor


How to deploy an application to WildFly with wildfly-maven-plugin


Posted on Saturday Feb 22, 2014 at 08:39AM in Jenkins


Environment

  • Jenkins 1.551
  • Apache Maven 3.1.1
  • git version 1.8.3.4 (Apple Git-47)
  • Oracle JDK7u51
  • OS X 10.9.1

Consideration of a way to achieve

  • There's the Deploy Plugin of Jenkins, but it only listed JBoss 5.x
  • Thus, I'm going to do deploy through Maven goal with wildfly-maven-plugin, not Jenkins Plugin.

Make pom.xml can deploy

Add wildfly-maven-plugin to pom.xml

  • According to [1], we need plugin definition like that.
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
            </plugin>
  • My whole pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.nailedtothex</groupId>
    <artifactId>hellojenkins</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
            </plugin>
        </plugins>
    </build>
</project>

Run mvn to deploy

According to [1], deploy command is:

mvn wildfly:deploy

Let's try

kyle-no-MacBook:hellojenkins kyle$ mvn clean package wildfly:deploy
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hellojenkins 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hellojenkins ---
[INFO] Deleting /Users/kyle/gits1/hellojenkins/hellojenkins/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hellojenkins ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /Users/kyle/gits1/hellojenkins/hellojenkins/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/kyle/gits1/hellojenkins/hellojenkins/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hellojenkins ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/kyle/gits1/hellojenkins/hellojenkins/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hellojenkins ---
[INFO] Surefire report directory: /Users/kyle/gits1/hellojenkins/hellojenkins/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Running hellojenkins.HelloBeanTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.043 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ hellojenkins ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hellojenkins] in [/Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/kyle/gits1/hellojenkins/hellojenkins/src/main/webapp]
[INFO] Webapp assembled in [19 msecs]
[INFO] Building war: /Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] >>> wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hellojenkins ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hellojenkins ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/kyle/gits1/hellojenkins/hellojenkins/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hellojenkins ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hellojenkins ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ hellojenkins ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hellojenkins] in [/Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/kyle/gits1/hellojenkins/hellojenkins/src/main/webapp]
[INFO] Webapp assembled in [5 msecs]
[INFO] Building war: /Users/kyle/gits1/hellojenkins/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.pom (11 KB at 1.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/28/commons-parent-28.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-parent/28/commons-parent-28.pom (49 KB at 94.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.pom (2 KB at 7.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.0.5/maven-core-3.0.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.0.5/maven-core-3.0.5.pom (6 KB at 20.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.pom (4 KB at 11.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.jar
Downloading: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.jar
Downloading: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar
Downloading: http://repo.maven.apache.org/maven2/org/jboss/remoting/jboss-remoting/4.0.0.Final/jboss-remoting-4.0.0.Final.jar
Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar (28 KB at 37.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-api/3.2.0.Final/xnio-api-3.2.0.Final.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.5/commons-compress-1.5.jar (251 KB at 252.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-nio/3.2.0.Final/xnio-nio-3.2.0.Final.jar
Downloaded: http://repo.maven.apache.org/maven2/org/tukaani/xz/1.2/xz-1.2.jar (93 KB at 83.0 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar (226 KB at 157.5 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-nio/3.2.0.Final/xnio-nio-3.2.0.Final.jar (95 KB at 149.7 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/jboss/xnio/xnio-api/3.2.0.Final/xnio-api-3.2.0.Final.jar (480 KB at 162.2 KB/sec)
Downloading: http://repository.jboss.org/nexus/content/groups/public/org/jboss/remoting/jboss-remoting/4.0.0.Final/jboss-remoting-4.0.0.Final.jar
Downloaded: http://repository.jboss.org/nexus/content/groups/public/org/jboss/remoting/jboss-remoting/4.0.0.Final/jboss-remoting-4.0.0.Final.jar (256 KB at 57.1 KB/sec)
2 22, 2014 10:07:18 午前 org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.0.Final
2 22, 2014 10:07:19 午前 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.0.Final
2 22, 2014 10:07:19 午前 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.0.Final
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.107s
[INFO] Finished at: Sat Feb 22 10:07:19 JST 2014
[INFO] Final Memory: 20M/245M
[INFO] ------------------------------------------------------------------------
kyle-no-MacBook:hellojenkins kyle$ 

Log of running WildFly:

10:07:19,623 INFO  [org.jboss.as.repository] (management-handler-thread - 13) JBAS014900: Content added at location /Users/kyle/apps/wildfly-8.0.0.Final/standalone/data/content/74/0b98a41a3c0830172a5df0c5c8d5fdc42be9b6/content
10:07:19,627 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015876: Starting deployment of "hellojenkins-0.0.1-SNAPSHOT.war" (runtime-name: "hellojenkins-0.0.1-SNAPSHOT.war")
10:07:19,649 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016002: Processing weld deployment hellojenkins-0.0.1-SNAPSHOT.war
10:07:19,661 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016005: Starting Services for CDI deployment: hellojenkins-0.0.1-SNAPSHOT.war
10:07:19,666 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016008: Starting weld service for deployment hellojenkins-0.0.1-SNAPSHOT.war
10:07:19,811 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017534: Registered web context: /hellojenkins-0.0.1-SNAPSHOT
10:07:19,832 INFO  [org.jboss.as.server] (management-handler-thread - 13) JBAS018559: Deployed "hellojenkins-0.0.1-SNAPSHOT.war" (runtime-name : "hellojenkins-0.0.1-SNAPSHOT.war")

The application works:

This works too if there's application already deployed which have same name.

Commit to repository

  • Commit changes of pom.xml so that Jenkins can execute the goal that tested above.

Make a Jenkins job

  1. Copy a job that created in previous post
  2. Edit the job that copied
    • Add maven goal “wildfly:deploy”
  3. Click “保存” in the bottom of the page

Run the job

  • I got some errors.
[INFO] XNIO version 3.2.0.Final
[INFO] XNIO NIO Implementation Version 3.2.0.Final
[INFO] JBoss Remoting version 4.0.0.Final
Authenticating against security realm: ManagementRealm
[ERROR] JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.038s
[INFO] Finished at: Sat Feb 22 13:44:10 JST 2014
[INFO] Final Memory: 20M/249M
[INFO] ------------------------------------------------------------------------
Jenkins????????????????
[ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) on project hellojenkins: Could not execute goal deploy on /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war. Reason: I/O Error could not execute operation '{
[ERROR] "operation" => "read-attribute",
[ERROR] "address" => [],
[ERROR] "name" => "launch-type"
[ERROR] }': java.net.ConnectException: JBAS012174: Could not connect to http-remoting://127.0.0.1:9990. The connection failed: Authentication failed: the server presented no authentication mechanisms
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/pom.xml to org.nailedtothex/hellojenkins/0.0.1-SNAPSHOT/hellojenkins-0.0.1-SNAPSHOT.pom
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
channel stopped
成果物を保存中
Finished: FAILURE

Why error?

  • In this setup, Jenkins and WildFly are running in different users
  • According to [7], there's an authentication mechanism called “JBoss Local User”, and maybe it can be used with same machine and user, and we might have been used it
  • But Jenkins has its own user in this setup
  • So, we may need another authentication mechanism.

Add a management user to WildFly

  • According to [7], properties file based authentication is enabled by default
  • We can use that command named “add-user” in $WILDFLY_HOME/bin to add a pair of username and password to properties file. usage:
./add-user.sh [USERNAME] [PASSWORD]
  • So let's make it one:
kyle-no-MacBook:bin kyle$ ./add-user.sh admin ***
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Added user 'admin' to file '/Users/kyle/apps/wildfly-8.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'admin' to file '/Users/kyle/apps/wildfly-8.0.0.Final/domain/configuration/mgmt-users.properties'
kyle-no-MacBook:bin kyle$
  • Restart of WildFly is not mandatory.

Edit and commit pom.xml

  • We have to add configuration element as a child of plugin element
                <configuration>
                    <username>USERNAME</username>
                    <password>PASSWORD</password>
                </configuration>
  • Now it is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.nailedtothex</groupId>
    <artifactId>hellojenkins</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
                <configuration>
                    <username>USERNAME</username>
                    <password>PASSWORD</password>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  • After edit, we have to commit it again.
  • I guess it is not good to write that environment specific variables like username and password in pom.xml, but I couldn't be found other better idea, so I just go this way this time.

A way to specify that username and password in the MAVEN_OPTS

  • According to [10], entries that wrote “User property is:” are can be specified in the MAVEN_OPTS. like that:
    • That configuration can be set after click “Advanced…” in the build section of configuration page of a project.
    • Now, we don't need to specify authentication information in pom.xml.

Run the job again

[INFO] --- maven-war-plugin:2.2:war (default-war) @ hellojenkins ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hellojenkins] in [/Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [3 msecs]
[INFO] Building war: /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/target/hellojenkins-0.0.1-SNAPSHOT.war
[WARNING] Failed to getClass for org.wildfly.plugin.deployment.DeployMojo
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) @ hellojenkins ---
[INFO] XNIO version 3.2.0.Final
[INFO] XNIO NIO Implementation Version 3.2.0.Final
[INFO] JBoss Remoting version 4.0.0.Final
Authenticating against security realm: ManagementRealm
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.672s
[INFO] Finished at: Sat Feb 22 14:37:01 JST 2014
[INFO] Final Memory: 21M/317M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/DeployToWildFly/workspace/hellojenkins/pom.xml to org.nailedtothex/hellojenkins/0.0.1-SNAPSHOT/hellojenkins-0.0.1-SNAPSHOT.pom
channel stopped
成果物を保存中
Finished: SUCCESS
  • Succeed but weird warning “Failed to getClass for org.wildfly.plugin.deployment.DeployMojo” remained.
    • I have googled it but there's no information about it.

Remarks

  • Maybe a way introduced at [8] can be a good idea to achieve that switch various deployment destinations.
    • We can switch the destination easily through use of Maven profiles
  • If you don't want to deploy when test failed, follow steps in [9] , and set parameter “-Dmaven.test.failure.ignore=false” to the MAVEN_OPTS.
  • When we have to deploy to remote Unix systems, Publish Over SSH Plugin[11] sounds very useful than the procedure of this post.

References

  1. WildFly Maven Plugin - Deploy/Undeploy Examples
  2. Eclipse Community Forums: Hudson » Deploy to Wildfly (jBoss 8.x?)
  3. The 10 Most Important Projects Hosted On Codehaus.org
  4. Deploy Plugin - Jenkins - Jenkins Wiki
  5. JenkinsでJBossAS7にデプロイしようと思ったので - 日々常々
  6. WildFly Maven Plugin - Deploy/Undeploy Examples
  7. Security Realms - WildFly 8 - Project Documentation Editor
  8. Jboss / Wildfly maven plugin to deploy on localhost/remote server
  9. [#JENKINS-959] hudson deploys maven artifact even if test has failed - Jenkins JIRA
  10. WildFly Maven Plugin - wildfly:deploy
  11. Publish Over SSH Plugin - Jenkins - Jenkins Wiki


How to define a JavaMail session using CLI


Posted on Sunday Feb 16, 2014 at 07:30AM in Technology


  • Defining a JavaMail session for gmail.

Environment

  • WildFly8.0.0.Final
  • Oracle JDK7u51

Defining with jboss-cli

Define a outbound-socket-binding named “MyMailSMTP”

  • SMTP server hostname
  • SMTP server port
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=MyMailSMTP:add( \
host=smtp.gmail.com, \
port=465)

Define a JavaMail session named “MyMail”

  • JNDI name of JavaMail session
  • Email address of the sender
  • Debug flag
/subsystem=mail/mail-session=MyMail:add(jndi-name="java:/mail/myMail", from="jane.doe@gmail.example.com", debug=true)

Add a reference from “MyMail” to “MyMailSMTP”

  • SMTP server username
  • SMTP server password
  • TLS flag
  • SSL flag
/subsystem=mail/mail-session=MyMail/server=smtp:add( \
outbound-socket-binding-ref=MyMailSMTP, \
ssl=true, \
username=jane.doe@gmail.example.com, \
password=***)

Example Servlet sends a mail

@WebServlet("/")
public class MailServlet extends HttpServlet {
    @Resource(lookup = "java:/mail/myMail")
    Session session;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        MimeMessage message = new MimeMessage(session);
        try {

            InternetAddress[] address = { new InternetAddress("jane.doe@icloud.example.com") };
            message.setRecipients(Message.RecipientType.TO, address);
            message.setSubject("test");
            message.setSentDate(new Date());
            message.setText("testbody");
            Transport.send(message);
        } catch (MessagingException ex) {
            throw new ServletException(ex);
        }
    }
}

Mail which sent from WildFly

Debug Log

15:37:26,305 INFO  [stdout] (default task-1) DEBUG: JavaMail version 1.5.1
15:37:26,306 INFO  [stdout] (default task-1) DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
15:37:26,307 INFO  [stdout] (default task-1) DEBUG: Tables of loaded providers
15:37:26,307 INFO  [stdout] (default task-1) DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
15:37:26,307 INFO  [stdout] (default task-1) DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
15:37:26,307 INFO  [stdout] (default task-1) DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
15:37:26,309 INFO  [stdout] (default task-1) DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
15:37:26,309 INFO  [stdout] (default task-1) DEBUG SMTP: need username and password for authentication
15:37:26,309 INFO  [stdout] (default task-1) DEBUG SMTP: useEhlo true, useAuth true
15:37:26,309 INFO  [stdout] (default task-1) DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
15:37:26,889 INFO  [stdout] (default task-1) 220 mx.google.com ESMTP *** - gsmtp
15:37:26,889 INFO  [stdout] (default task-1) DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
15:37:26,889 INFO  [stdout] (default task-1) 
15:37:26,893 INFO  [stdout] (default task-1) EHLO ***
15:37:27,006 INFO  [stdout] (default task-1) 250-mx.google.com at your service, [27.114.70.39]
15:37:27,006 INFO  [stdout] (default task-1) 250-SIZE 35882577
15:37:27,006 INFO  [stdout] (default task-1) 250-8BITMIME
15:37:27,006 INFO  [stdout] (default task-1) 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
15:37:27,007 INFO  [stdout] (default task-1) 250-ENHANCEDSTATUSCODES
15:37:27,007 INFO  [stdout] (default task-1) 250 CHUNKING
15:37:27,007 INFO  [stdout] (default task-1) DEBUG SMTP: Found extension "SIZE", arg "35882577"
15:37:27,007 INFO  [stdout] (default task-1) DEBUG SMTP: Found extension "8BITMIME", arg ""
15:37:27,007 INFO  [stdout] (default task-1) DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
15:37:27,008 INFO  [stdout] (default task-1) DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
15:37:27,008 INFO  [stdout] (default task-1) DEBUG SMTP: Found extension "CHUNKING", arg ""
15:37:27,008 INFO  [stdout] (default task-1) DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
15:37:27,008 INFO  [stdout] (default task-1) DEBUG SMTP: AUTH LOGIN command trace suppressed
15:37:27,959 INFO  [stdout] (default task-1) DEBUG SMTP: AUTH LOGIN succeeded
15:37:27,960 INFO  [stdout] (default task-1) DEBUG SMTP: use8bit false
15:37:27,960 INFO  [stdout] (default task-1) MAIL FROM:<jane.doe@gmail.example.com>
15:37:28,074 INFO  [stdout] (default task-1) 250 2.1.0 OK *** - gsmtp
15:37:28,074 INFO  [stdout] (default task-1) RCPT TO:<jane.doe@icloud.example.com>
15:37:28,194 INFO  [stdout] (default task-1) 250 2.1.5 OK *** - gsmtp
15:37:28,195 INFO  [stdout] (default task-1) DEBUG SMTP: Verified Addresses
15:37:28,195 INFO  [stdout] (default task-1) DEBUG SMTP:   jane.doe@icloud.example.com
15:37:28,195 INFO  [stdout] (default task-1) DATA
15:37:28,881 INFO  [stdout] (default task-1) 354  Go ahead *** - gsmtp
15:37:28,881 INFO  [stdout] (default task-1) Date: Thu, 6 Mar 2014 15:37:26 +0900 (JST)
15:37:28,881 INFO  [stdout] (default task-1) To: jane.doe@icloud.example.com
15:37:28,881 INFO  [stdout] (default task-1) Message-ID: <56980149.1.1394087846308.JavaMail.jane.doe@gmail.example.com>
15:37:28,882 INFO  [stdout] (default task-1) Subject: test
15:37:28,882 INFO  [stdout] (default task-1) MIME-Version: 1.0
15:37:28,882 INFO  [stdout] (default task-1) Content-Type: text/plain; charset=us-ascii
15:37:28,882 INFO  [stdout] (default task-1) Content-Transfer-Encoding: 7bit
15:37:28,882 INFO  [stdout] (default task-1) 
15:37:28,882 INFO  [stdout] (default task-1) testbody
15:37:28,883 INFO  [stdout] (default task-1) .
15:37:29,802 INFO  [stdout] (default task-1) 250 2.0.0 OK 1394087849 *** - gsmtp
15:37:29,803 INFO  [stdout] (default task-1) QUIT
15:37:29,916 INFO  [stdout] (default task-1) 221 2.0.0 closing connection *** - gsmtp
  • Debug logging can be turned off like this:
/subsystem=mail/mail-session=MyMail:write-attribute(name=debug, value=false)
/:reload

References

  1. How to configure a Mail Session in Wildfly? | Community
  2. JBoss AS 7.2.0 Email Session configurtion - Eng… | Community
  3. jboss7.x - Please help configure JBoss 7 “mail-session” via jboss-cli - Stack Overflow
  4. Configuring and Using mail service in JBoss AS7 « JBoss
  5. JBoss 7 JavaMail | Community