Setting svn mime-types using Apache Ant

Here is the source code of an Apache Ant build file (build.xml) to set SVN mime-types recursively on a javadoc folder (useful to publish Javadoc on google source code for example)

<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="default">

	<taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="/path/to/ant-contrib-library"/>
        </classpath>
    </taskdef>

	<property name="srcdir" location="/path/to/source-folder-javadoc-for-example" />
	
    <!-- ================================= 
          target: default              
         ================================= -->
    <target name="default" description="description">
    	<for param="file">
    		<path>
				<fileset dir="${srcdir}">
					<include name="**/*.html" />
				</fileset>
			</path>
    		<sequential>
    			<antcall target="mime">
    				<param name="file" value="@{file}" />
    				<param name="mime-type" value="text/html" />
    			</antcall>
			</sequential>
		</for>
		<for param="file">
    		<path>
				<fileset dir="${srcdir}">
					<include name="**/*.css" />
				</fileset>
			</path>
    		<sequential>
    			<antcall target="mime">
    				<param name="file" value="@{file}" />
    				<param name="mime-type" value="text/css" />
    			</antcall>
			</sequential>
		</for>
    	<for param="file">
    		<path>
				<fileset dir="${srcdir}">
					<include name="**/*.jpeg" />
				</fileset>
			</path>
    		<sequential>
    			<antcall target="mime">
    				<param name="file" value="@{file}" />
    				<param name="mime-type" value="image/jpeg" />
    			</antcall>
			</sequential>
		</for>
    </target>
	
	<target name="mime">
		<exec executable="d:/tools/slik-svn/bin/svn.exe">
			 <arg value="propset" />
			 <arg value="svn:mime-type" />
			 <arg value="${mime-type}" />
			 <arg value="${file}"/>
		</exec>
	</target>

</project>

References

Advertisements

Java Derby and Hibernate 3.x configuration using annotations

Key words
Java 1.6, JPA, Java Derby database, Hibernate 3.x, Maven 2.x or higher

Note that this post is based on a Maven project.

Project dependencies
Project basic configuration and dependencies list (in the pom.xml file)

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>3.5.6-Final</version>
		</dependency>
		<dependency>
			<groupId>javassist</groupId>
			<artifactId>javassist</artifactId>
			<version>3.12.0.GA</version>
		</dependency>
		<dependency>
			<groupId>org.apache.derby</groupId>
			<artifactId>derby</artifactId>
			<version>10.8.2.2</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.derby</groupId>
			<artifactId>derbyclient</artifactId>
			<version>10.8.2.2</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-annotations</artifactId>
			<version>3.5.6-Final</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>javax.persistence</groupId>
			<artifactId>persistence-api</artifactId>
			<version>1.0.2</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.6</version>
		</dependency>
	</dependencies>

Hibernate configuration
Hibernate basic configuration; the hibernate.cfg.xml file (in the src/main/resources/ folder)

<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

	<session-factory>

		<!-- Database connection settings -->
		<property name="connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
		<property name="connection.url">jdbc:derby:data;create=true</property>
		<property name="connection.username">application</property>
		<property name="connection.password">password</property>
		
		<property name="hibernate.default_schema">my_application</property>

		<!-- JDBC connection pool (use the built-in) -->
		<property name="connection.pool_size">1</property>

		<!-- SQL dialect -->
		<property name="dialect">org.hibernate.dialect.DerbyDialect</property>

		<!-- Enable Hibernate's automatic session context management -->
		<property name="current_session_context_class">thread</property>

		<!-- Disable the second-level cache -->
		<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

		<!-- Echo all executed SQL to stdout -->
		<property name="show_sql">true</property>

		<!-- Drop and re-create the database schema on startup -->
		<property name="hbm2ddl.auto">update</property>

		<mapping class="com.ichir.projects.entities.Entity1" />
		<mapping class="com.ichir.projects.entities.Entity2" />

	</session-factory>

</hibernate-configuration>
  • jdbc:derby:data;create=true Once the Hibernate session is instantiated for the first time, the Database is created in the data folder
  • hbm2ddl.auto set to update The tables are created on demand.
  • All the JPA annotated classes are declared in the mapping class tags

Instantiation and Bootraping
Initialize the factory

	public SessionFactory getFactory() {
		if (factory == null) {
			synchronized (MyClass.class) {
				if (factory == null) {
					SessionFactory factory = new AnnotationConfiguration()
					  .configure()
					  .buildSessionFactory();
				}
			}
		}
		return factory;
	}

Working with entities

	Session session = getFactory().openSession();
	// do CRUD operations on entities, please refer to JPA and Hibernate for that
	session.close();

That’s all folks!

Downloads

References

Developping and deploying webservice onto Tomcat

Deploying Webservices onto Tomcat is possible with the metro library.

Below is concise description on how to achieve that.

Configuration
Add to your web.xml the following servlet configuration

<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
    <servlet-name>service</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>service</servlet-name>
    <url-pattern>/MyService/*</url-pattern>
</servlet-mapping>

Here we add the metro listener on startup WSServletContextListener to initialize the Webservice context. We declare the Servlet (metro servlet) WSServlet and bind it to the context MyService (the context MyService name here is arbitrary).

To finalize configuration, create next to your web.xml (generally in the WEB-INF folder), the sun-jaxws.xml file with the following content

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
    <endpoint name="service" implementation="com.ichir.projects.services.ServiceImpl" url-pattern="/MyService" />
</endpoint

As you can see, in this file, we bind the Webservice context (MyService) to the webservice implementation class com.ichir.projects.services.ServiceImpl.

The webservice implementation class (a simple Calculator/Summer) is a regular @Webservice annotated class

package com.ichir.projects.services;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public class ServiceImpl {
	public int calculate(@WebParam(name="a") int arg0, @WebParam(name="b") int arg1) {
		return arg0 + arg1;
	}
}

Deploy your webservice onto Tomcat and enjoy!

Downloads

References

Context

  • Maven 2 or higher
  • Servlet API 2.5
  • Metro library 2.2.x