Skip to content

Instantly share code, notes, and snippets.

@friek
friek / Enumerate.java
Last active December 15, 2015 10:59
A java enumerate with a static fromString method to get an enum by String value.
public enum Enumerate
{
VALUE1("VALUE1"),
VALUE2("VALUE2"),
UNKNOWN("UNKNOWN");
private String value;
private Enumerate(String s)
{
value = s;
@friek
friek / pom-compiler-level.xml
Created March 26, 2013 22:11
Set the java compiler level in pom.xml.
<!-- in pom.xml -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
@friek
friek / pom-project-encoding.xml
Created March 26, 2013 22:12
Set the project source and output encoding in a maven project (in pom.xml).
<!-- in pom.xml -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
@friek
friek / tomcat-jndi-c3p0-mysql.xml
Created March 26, 2013 22:14
Tomcat JNDI configuration for mysql and C3P0 pooling. Also runs an anti-idle query to prevent MySQL from disconnecting idle connections.
<Resource acquireIncrement="1" auth="Container" driverClass="com.mysql.jdbc.Driver"
factory="org.apache.naming.factory.BeanFactory"
idleConnectionTestPeriod="600" initialPoolSize="2"
jdbcUrl="jdbc:mysql://<server>:3306/<dbname>?characterEncoding=UTF-8"
maxIdleTime="300" maxPoolSize="3" minPoolSize="1" name="jdbc/<resource_name>"
password="<password>" preferredTestQuery="SELECT 1"
testConnectionOnCheckout="true" type="com.mchange.v2.c3p0.ComboPooledDataSource"
user="<username>" />
@friek
friek / JunitSkipTest.java
Last active December 16, 2015 04:49
Skip JUnit test conditionally
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import org.junit.BeforeClass;
import org.junit.Test;
public class JunitSkipTest
{
@BeforeClass
public static void setUpTest()
{
@friek
friek / skip_maven_jars.xml
Created April 13, 2013 21:12
Exclude certain jars in a maven war build.
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- Exclude servlet-api-2.5.jar from the lib dir -->
<packagingExcludes>WEB-INF/lib/servlet-api-2.5.jar</packagingExcludes>
<!-- Exclude all log4j jars from the lib dir -->
<packagingExcludes>WEB-INF/lib/*log4j*.jar</packagingExcludes>
@friek
friek / SortMap.java
Last active December 17, 2015 00:38
Sort a map by value.
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Shamelessly stolen from
* http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java/2581754#2581754
@friek
friek / mysqldefault.ini
Created October 14, 2013 20:03
Useful default MySQL settings.
[mysqld]
; Default server character set
character-set-server = utf8
; Bind to all addresses (including IPv6).
bind-address = ::
[mysql]
; Default client character set.
default-character-set = utf8
@friek
friek / jboss-as7-mysql-ds.xml
Last active January 1, 2016 18:59
jboss-as7-mysql-ds.xml is part of the standalone.xml in which the MySQL datasource is defined. module.xml is the XML file necessary for configuring the MySQL connector module for JBoss AS 7.1.1. This file needs to be stored in $JBOSS_HOME/modules/com/mysql/main along with mysql-connector-java-5.1.25.jar.
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true">
<connection-url>jdbc:mysql://*hostname*:3306/*dbname*?characterEncoding=UTF-8</connection-url>
<driver>com.mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>true</prefill>
@friek
friek / pom.xml
Created April 22, 2014 20:58
Basic pom.xml for arquillian profiles for both the embedded weld ee container and the Wildfly app server
<?xml version="1.0" encoding="UTF-8"?>
<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>nl.localhost.test</groupId>
<artifactId>arquillian</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>