Maven - Generating Code with JAXB Plugin

We wanted to generate sources from multiple scattered XSDs. These schema definition files described classes in different packages with the same prefix. The setting for such configuration is not so straightforward  so I put together this small working example.

Possible sources of problems:
  1. Plugin uses lock file to determine when schema files are newer than generated files. Using the the same or default lock file name causes only first xjc plugin execution is run.
  2. By default the destination directory is cleared. With different XSDs targeting the sub-directories of the same directory you likely get that later executions deleting previously generated sources.









Intellij Idea - Searching in Single Library with Scopes

Do you have a package in your dependencies and need to seach for some string in just this package, excluding others ?

You can do it using not so known scopes. If you do not know them, you should try, it's one of the most practical things Idea includes. It can be used e.g. for coloring your tabs but it's also more than useful for searching.

1/ Open Find in Path dialog, either from menu or via Ctrl+Shift+F shortcut 

 2/ Select Scopes - Custom.
 3/ For creating of a new scope, click on three dot buton on the right side of the scopes list.
 4/ in Scopes dialog, use the Add Scope icon (yellow plus in topl left corner). In the right panel select packages belonging to the library in which you want to search and include them recursively and press Apply.
 5/ Giving OK you'll get back to the search dialog now with your newly created scope available.


Deploying WAR Locally and Remotely (via scp)

Tried to run ant scp from maven and got weird class org.apache.tools.ant.taskdefs.optional.ssh.Scp was not found, even when you have all the ant-jsch and jsch jar files in ant lib directory ? Try to add ant-jsch as plugin's dependency in maven:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <name>Example project</name>





                 todir="local_deolpy_dir_name" />
                 todir="login:password@remote_host_name:remote_deploy_dir_name" />





Apache-Tomcat Communication via mod_jk

Ever wondered why to use mod_jk and how to set it up? The reasons why are simple - Tomcat guys recommend it as more mature.

It certainly has better logging then mod_ajp_proxy and that helps alot during troubleshooting or performance tuning. The ability to set max packet size above 8kB is also a good point for some deployments. As for performance, some tests showed slight advantage of mod_jk to mod_ajp_proxy, but the main seemed to be the usage of Tomcat's native module regardless of AJP module used.

LoadModule jk_module /usr/lib/httpd/modules/mod_jk.so

# points to a file that provides a mapping between a worker name and a valid worker type
JkWorkersFile /etc/httpd/conf/worker.properties
JkLogFile /var/log/httpd/mod_jk.log

# allows log levels: debug, info, error
JkLogLevel   info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat      "%w %V %T"

# JkOptions - see http://tomcat.apache.org/connectors-doc/reference/apache.html

<Location /jkstatus/>
 JkMount status
 # Order deny,allow
 # Deny from all
 # Allow from
 Allow from all

<VirtualHost *:80>
  # which URI contexts are sent to a ASF Tomcat worker - exact, context or suffix match
  JkMount /* tomcat1

Note: JkMount must be defined in VirtualHost to work.



## when using mpm prefork, the pool_size should be set to "1"


JkWorkerProperty directive allows to move content of the worker.properties file to apache config.


JBossCache JMX in Standalone App

MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName on = new ObjectName("jboss.cache:service=Cache");
JmxRegistrationManager jmxManager = new JmxRegistrationManager(server, cache, on);
catch (MalformedObjectNameException ex)
log.error( CommonUtils.getStackTraceString(ex) );

If you want to read cache statistic in the same JVM, get JMX object name of
CacheMgmtInterceptor using jconsole and use it to access its attributes:
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("jboss.cache:service=Cache,jmx-resource=CacheMgmtInterceptor");

Probably the most interesting attributes are named Hits, Misses, HitMissRatio, Evictions, AverageReadTime, AverageWriteTime, ReadWriteRatio and NumberOfNodes. More can be found in documentation. Note that Hits and Misses are on attribute level so if work with whole nodes, these values are useless, also when putting whole nodes into the cache the interceptor is probably bypassed.