background preloader


Facebook Twitter

Creating Custom Directives for Apache Velocity. Java Velocity In this article we will go over Apache Velocity API and write our own inline and block directives.

Creating Custom Directives for Apache Velocity

Like in the previous article about creating Velocity tools, we will be trying to duplicate the behavior of truncate() method from DisplayTools which truncates a long string. There are two directive types in Velocity - inline and block directives. Inline directives consist from a single line, while block directives have body and closing tag #end: #include( "one.gif","two.txt","three.htm" ) #if( $foo ) Block directive... Creating inline directive To declare your custom directive you need to specify userdirective parameter in velocity config (for example in file) and provide comma separated list of complete user directive class names: Configuring The JSON Default Provider (jettison) in TomEE.

Configuring The JSON Default Provider (jettison) in TomEE TomEE comes with Jettison and cxf as standard JAXB and JAX-RS providers.

Configuring The JSON Default Provider (jettison) in TomEE

Jettison is "chatty" and might require some tweaking. To tweak Jettison in a WAR deployment, you will have to provide two configuration files: The first src/main/webapp/WEB-INF/resources.xml configures the JSON provider: <? In the /src/main/webapp/WEB-INF/openejb-jar.xml descriptor, you only have to refer to the earlier defined configuration: <openejb-jar xmlns=" xmlns:xsi=" xsi:schemaLocation=" class-name="jaxrs-application"><properties> cxf.jaxrs.providers = jsonProvider </properties></pojo-deployment></openejb-jar> TomEE greatly simplifies the configuration--checkout the CXF standalone example as reference / comparison.

See you at Java EE Workshops at Munich Airport, Terminal 2 or on demand and in a location very near you:! Posted at 04:15AM Nov 10, 2014 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | | Views/Hits: 1952. Java-Latte: Don't know which map/collection to use? I have prepared the flow diagram to show simplest way to know which collection to used.

Java-Latte: Don't know which map/collection to use?

To know more about brief introduction to Collection Framework check this post I hope this diagram also help you a lot to summarize about collection. If you know anyone who has started learning java, why not help them out! Just share this post with them. Thanks for studying today!... Using Maven profiles and resource filtering. Posted by Paolo Predonzani on June 23, 2009 Introduction In this tutorial I'll explain how to deal with multiple deployment environments (such as development and production) from a configuration perspective.

Using Maven profiles and resource filtering

Specifically I'll show how environment-specific configurations, such as database connections and resource contents, can be "managed" in a centralized way by the developer. This tutorial assumes some working knowledge of Maven overlays. Adding Unmanaged Dependencies to a Maven Project. Java Table of Contents Some Java applications have dependencies that aren’t available in a public Maven repository.

Adding Unmanaged Dependencies to a Maven Project

This guide shows you how to add these libraries in your application project and tell Maven how to find them. Pick groupId, artifactId and version parameters. Tomcat JDBC Connection Pool configuration for production and development. As mentioned in the post Install Eclipse Kepler 64 bit on Windows 7 64 bit, uses Apache Tomcat 7 as application server.

Tomcat JDBC Connection Pool configuration for production and development

This post presents how the Tomcat JDBC Connection Pool is configured in development and production for The used database is MySql. The Tomcat Connection pool is configured as a resource described in The Tomcat JDBC documentation with the only difference being that you have to specify the factory attribute and set the value to org.apache.tomcat.jdbc.pool.DataSourceFactory. For, it is configured in the context.xml file of the web application: Production environment Production environment configuration Sizing the conection pool initialSize = 34 – the initial number of connections that are created when the pool is startedmaxActive = 377 – the maximum number of active connections that can be allocated from this pool at the same time.

Validate connections Connection leaks The validation/cleaner thread. Java - Get the server port number from tomcat with out a request. Manipulating Files in Java 7. The following is a modified snippet from a draft of The Well-Grounded Java Developer.

Manipulating Files in Java 7

It gives you a quick taster of how much easier it is to manipulate files in Java 7 than in previous versions. By using the new Files class and its many utility methods, you can perform the following operations on files with only a single line of code: CreateDeleteCopyMove/Rename TIP A quick note on Path. This post assumes you have some passing familiarity with the new Java 7 Path class, if not here’s a quick introduction! Let’s start by looking at the creation and deletion of files. Creating and Deleting files By using the simple helper methods in the Files class you can create files and delete them easily as well. TIP If you are running the code snippets in this section, replace the actual paths with ones that match your file system! The following code snippet shows basic file creation, using the Files.createFile(Path target) method.