Archive for the ‘Java’ Category

Java: Encoding UTF8 Java_tools

Thursday, July 11th, 2013

on unix systems (linux, Mac) set the following in your .profile or equivalent.

export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8

On windows, setting the (Windows) environment variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8, the (Java) System property will be set automatically every time a JVM is started.

source

Java: Performance monitoring Jamon to JavaSimon

Wednesday, October 24th, 2012

JAMONAPI was a great Java Library for programatic Java monitoring, but it is not really well maintained anymore

JavaSimon is relatively recent, similar to Jamon, and is actively supported. From a core monitoring point of view, it seems to have everything Jamon had, even more (nano second, nested monitor)

Here is the Jamon vs JavaSimon story

Java Guava Sorting

Sunday, August 12th, 2012
Comparator byLastName = new Comparator() {
    public int compare(final Person p1, final Person p2) {
        return p1.getLastName().compareTo(p2.getLastName());
    }
};
Comparator byFirstName = new Comparator() {
    public int compare(final Person p1, final Person p2) {
        return p1.getFirstName().compareTo(p2.getFirstName());
    }
};

List sortedCopy = Ordering.from(byLastName).compound(byFirstName).reverse().sortedCopy(persons);

Great article about Guava Function, Predicates, Sorting and filter HERE

Maven: Pom.xml and AspectJ

Monday, March 26th, 2012

In the Lib that has the aspect, add this to the pom.xml

<!-- AspecJ Compile -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <outxml>true</outxml>
    <showWeaveInfo>true</showWeaveInfo>
    <verbose>true</verbose>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- /AspecJ Compile -->

.....


<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>1.6.7</version>
</dependency>

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.6.7</version>
</dependency>

Then, on the application that receive the aspect, need to have the failOnError:false to allow the mvn compiler to continue. Then, we weave the dependency “LibWithSomeAspects” in.

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <!-- Temporary fix for supporting aspectJ -->
    <failOnError>false</failOnError>
  </configuration>
</plugin>

<!-- AspecJ Compile -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <outxml>true</outxml>
    <showWeaveInfo>true</showWeaveInfo>
    <verbose>true</verbose>
    <weaveDependencies>
      <weaveDependency>
        <groupId>com.example</groupId>
        <artifactId>LibWithSomeAspects</artifactId>
      </weaveDependency>
    </weaveDependencies>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- /AspecJ Compile -->

CSS: Less JavaScript and Java Less Processor

Thursday, February 23rd, 2012

less

Asual Java Less processor (not on maven central yet ;(

Java: json parser and serializer

Sunday, February 19th, 2012

Jackson

Check the later Jackson JSON Parser core release (apache source license) for the latest version.

<dependency>
	<groupId>org.codehaus.jackson</groupId>
	<artifactId>jackson-mapper-asl</artifactId>
	<version>1.9.4</version>
</dependency>

All Jackson Maven Dependencies

Java: Eclipse Copyright Plugins to easily update java file headers

Monday, February 13th, 2012

Copyright Plugins

Google API References

Sunday, December 11th, 2011

Java: C3P0 Maven (and hibernate c3p0 maven) and quick start

Saturday, May 21st, 2011
<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "org.postgresql.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:postgresql://localhost/testdb" );
cpds.setUser("swaldman");
cpds.setPassword("test-password");

// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(5);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(20);

// The DataSource cpds is now a fully configured and usable pooled DataSource

...

Cleaning up on app shutdown

DataSources.destroy( cpds );

c3p0 Doc

For Hibernate, the maven dist is

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-c3p0</artifactId>
  <version>3.5.1-Final</version>
</dependency>

Java: slf4j log factory initialization

Saturday, May 21st, 2011
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(AnyClass.class);