Kohei Nozaki's blog 

Entries tagged [wildfly]

Using multiple instances of WildFly on shared home directory


Posted on Saturday Jan 24, 2015 at 10:34AM in Technology


Sometimes I need to use multiple instances of WildFly, but it’s annoying to copy whole WildFly package for every needs. also it consumes many diskspace (it’s over 100MB per instance!). an instance means a configuration (deployed applications, registered JDBC driver, datasource, job repository of batch and so on) in this entry.

I leave this entry as a my note of a way to use multiple instances that sharing the home directory (core modules of WildFly) except configuration.

Explode the tarball of WildFly.

tar zxvf ~/Downloads/wildfly-8.2.0.Final.tar.gz

Copy the standalone directory for numbers that you want to use.

cd wildfly-8.2.0.Final
cp -rpv standalone standalone-1
cp -rpv standalone standalone-2

Launch an instance on a specified base directory.

bin/standalone.sh -Djboss.server.base.dir=/Users/kyle/servers/wildfly-8.2.0.Final/standalone-1

Also -Djboss.socket.binding.port-offset=100 parameter is useful for using multiple instance at same time. it makes WildFly to apply a offset for all of number of ports to listen. for example, following instances can be running at the same time with its own configuration and same core modules:

bin/standalone.sh -Djboss.server.base.dir=/Users/kyle/servers/wildfly-8.2.0.Final/standalone-1 -Djboss.socket.binding.port-offset=100
bin/standalone.sh -Djboss.server.base.dir=/Users/kyle/servers/wildfly-8.2.0.Final/standalone-2 -Djboss.socket.binding.port-offset=200

Note that if you use port offset and when you want to use jboss-cli, you need to start jboss-cli with an additional parameter for each instances like following:

./jboss-cli.sh --controller=localhost:10090 --connect

Configuring IntelliJ IDEA.

  1. Open Edit Configurations…​ on the drop down list in upper right corner

  2. Add Local JBoss Server instance

  3. Press Configure…​

  4. Press + button in upper left corner of the window

  5. Enter /Users/kyle/servers/wildfly-8.2.0.Final and press OK twice

  6. Put -Djboss.server.base.dir=/Users/kyle/servers/wildfly-8.2.0.Final/standalone-1 to VM options

  7. Put 100 to Port offset

  8. Press OK

Now you can use same Application server for each Run Configuration. you only need to copy original standalone directory and specify jboss.server.base.dir and Port offset for each projects that needed to manage separately.

Note: the size of standalone directory is around 150K. so reasonable.

kyle-no-MacBook:wildfly-8.2.0.Final kyle$ du -sh standalone
136K	standalone

References


Evaluating JRebel for WildFly and IntelliJ IDEA


Posted on Wednesday Jan 21, 2015 at 10:41PM in Technology


I’m evaluating myJRebel which is free, for personal, non-commercial use only version of JRebel. it enables hot-deployment of classes. its quick start guide for IntelliJ IDEA is nice and easy to understand.

I used an example project which used in my past posting Exploded deployment for WildFly on development and Conditional inclusion of whole element for deployment descriptor with Maven for evaluate JRebel.

Installation is very easy. we can just follow the quick start guide. my recipe is as follows:

  1. Just find and install JRebel plugin from plugin installation window of IntelliJ IDEA

  2. After restart, enter your activation key (get yours from https://my.jrebel.com/) in Help ⇒ JRebel Activation window

  3. Add a definition of JRebel Maven Plugin. I prefer to put definition to a profile because sometimes I make my project public on GitHub or somewhere and not everyone can use JRebel

    <profile>
        <id>jrebel</id>
        <build>
    	<plugins>
    	    <plugin>
    		<groupId>org.zeroturnaround</groupId>
    		<artifactId>jrebel-maven-plugin</artifactId>
    		<version>1.1.5</version>
    		<executions>
    		    <execution>
    			<id>generate-rebel-xml</id>
    			<phase>process-resources</phase>
    			<goals>
    			    <goal>generate</goal>
    			</goals>
    		    </execution>
    		</executions>
    	    </plugin>
    	</plugins>
        </build>
    </profile>
  4. Enable a profile named jrebel in Maven Projects window (make sure to check if /WEB-INF/classes/rebel.xml exists in the target directory after build)

  5. Launch your application server with a newly added Run with JRebel icon on upper-right. you would see some logging messages from JRebel in your console

After installation, I did some experiment that modifying a method of CDI managed bean which returns a constant string. it works fine, and pressing Command+F9 (Make Project) after modification is good so that JRebel can reflects changes immediately. also Update classes and resources On frame deactivation works fine but I felt some delay to reflect for about 1 or 2 seconds.

It works fine during the evaluation and it was very nice. it properly enabled server side Java development without deployment. I would apply it to my project.

Also I found a book named "Instant JRebel" (published on 2013). I haven’t read it but it might be good for beginners.


Exploded deployment for WildFly on development


Posted on Tuesday Jan 20, 2015 at 07:25PM in Technology


I used archive deployment for long time on development because of this problem: http://stackoverflow.com/questions/24725644/intellij-idea-artifact-xxxxwar-exploded-has-invalid-extension

Archive deployment needs redeploy for reflect updates of every resource even if I updated only static content such as html, css, xhtml and jsp. it’s very annoying but finally I found a solution to use exploded deployment with WildFly and IntelliJ IDEA for WAR application so I leave some notes about it. my environment is WildFly 8.2.0.Final and IntelliJ IDEA 14.0.2.

First, specify webappDirectory which ended with .war to pom.xml in your project so that make WildFly to stop complaining that there’s no suffix to application directory.

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <webappDirectory>${project.build.directory}/exploded/${project.build.finalName}.war</webappDirectory>
    </configuration>
</plugin>

According to https://youtrack.jetbrains.com/issue/IDEA-86484, this should be worked for EAR deployments:

<workDirectory>${project.build.directory}/myapp.ear</workDirectory>

Set following attributes to WildFly with jboss-cli for JSP hot-deployment:

/subsystem=undertow/servlet-container=default/setting=jsp:write-attribute(name=development, value=true)
/subsystem=undertow/servlet-container=default/setting=jsp:write-attribute(name=check-interval, value=1)
/subsystem=undertow/servlet-container=default/setting=jsp:write-attribute(name=modification-test-interval, value=1)
/subsystem=undertow/servlet-container=default/setting=jsp:write-attribute(name=recompile-on-fail, value=true)
:reload

Set following parameters to web.xml for JSF(XHTML) hot-deployment:

<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>0</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

REFRESH_PERIOD should be 2 (default) or something for production environment (filtering with maven might help). also it’s better to specify PROJECT_STAGE in JNDI.

Then configure your IDE.

for IntelliJ IDEA

  1. Click the empty drop down list on upper right then select Edit Configurations…​

    84aac7bd fd1b 4157 b840 3d2aacaf7f6b
  2. Click "+" button on upper left then select JBoss Server ⇒ Local

    74253f62 b95c 4a4d 8b00 72deac5a570b
  3. Click "Fix" on the lower right then select an artifact which ended with "exploded"

    fc2afc60 995d 4668 8840 9c3b241dd5a7
  4. Back to server tab and select desirable actions. I prefer "Update resources" for On frame deactivation because it enables that I can check modified JSP/XHTMLs with just press Command+Tab to switch to browser and reload immediately. I can trigger redeploy by hand with Command+F10 shortcut when I update some classes.

    1ff45e5f ec93 4a4c a379 7bf73ff1b138
  5. Now you can launch WildFly with the button on the upper right.

    0a5a41bc 98a8 45ab b08a db3e31e725d8

Refer http://jrebel.com for hot deployment of classes. it also offers free https://my.jrebel.com for personal, non-commercial use.


Multiple deployment use mode is implemented to jberetweb


Posted on Thursday Jan 15, 2015 at 09:06PM in jberetweb


Now jberetweb can operate (start, stop, etc) distributed batches in multiple deployment. to enable multiple deployment use mode, suppress -DjobOperator.jndi and specify -DjobOperator.name=${facade-class-name} (e.g. JobOperatorFacade) in mvn option when you build it.

In multiple deployment use mode, "App Name" column will be added for grasp where is deployment of each job comprehensively. actions such as restart, stop will be executed through lookup of appropriate remote EJB interface in according to "App Name".

8eb794ca c389 4590 bc0a 643507e66c3a

Also in Start Job window, "App Name" can be specified. this will lookup appropriate remote interface accordingly too.

905367a9 1944 4025 bf2c 0623571313b0


How to set default-encoding of Undertow


Posted on Sunday Jan 11, 2015 at 09:57AM in Technology


Launch jboss-cli and connect to WildFly, then enter following and reload:

/subsystem=undertow/servlet-container=default:write-attribute(name=default-encoding,value=UTF-8)
This may solves corruption of multi-byte characters (such as "????") like JSP on Japanese environment or contents. この設定で日本語環境におけるJSPの文字化け等を防げる場合があります.