Commits

Micha Kops committed 45106c4

initial import.

  • Participants

Comments (0)

Files changed (4)

+.settings
+.classpath
+.project
+target
+
+# About #
+
+Examples for the creation of timer/cron jobs in a Java EE 6 environment running on an embedded GlassFish application server.
+
+Please feel free to visit my blog at [www.hascode.com] for the full tutorial.
+
+  [www.hascode.com]:http://www.hascode.com/
+  
+<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>com.hascode.tutorial</groupId>
+	<artifactId>jee6-timerservice-tutorial</artifactId>
+	<version>1.0.0</version>
+	<packaging>war</packaging>
+	<name>jee6-timerservice-tutorial</name>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.glassfish.main.extras</groupId>
+			<artifactId>glassfish-embedded-all</artifactId>
+			<version>3.1.2</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax</groupId>
+			<artifactId>javaee-web-api</artifactId>
+			<version>6.0</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<finalName>timerapp</finalName>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>2.1.1</version>
+				<configuration>
+					<failOnMissingWebXml>false</failOnMissingWebXml>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.glassfish</groupId>
+				<artifactId>maven-embedded-glassfish-plugin</artifactId>
+				<version>3.1.1</version>
+				<configuration>
+					<app>${project.build.directory}/${project.build.finalName}.war</app>
+					<port>8080</port>
+					<contextRoot>${project.build.finalName}</contextRoot>
+					<name>${project.build.finalName}</name>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<repositories>
+		<repository>
+			<id>java.net-public-repository-group</id>
+			<name>Java.Net Public Maven Repository Group</name>
+			<url>https://maven.java.net/content/groups/public</url>
+		</repository>
+		<repository>
+			<id>java.net-staging-repository-group</id>
+			<name>Java.Net Staging Maven Repository Group</name>
+			<url>https://maven.java.net/content/groups/staging</url>
+		</repository>
+		<repository>
+			<id>java.net-releases-repository-group</id>
+			<name>Java.Net Releases Maven Repository Group</name>
+			<url>https://maven.java.net/content/repositories/releases</url>
+		</repository>
+		<repository>
+			<id>java.net-snapshots-repository-group</id>
+			<name>Java.Net Snapshots Maven Repository Group</name>
+			<url>https://maven.java.net/content/repositories/snapshots</url>
+		</repository>
+		<repository>
+			<id>apache-snapshot</id>
+			<url>https://repository.apache.org/content/repositories/snapshots/</url>
+		</repository>
+	</repositories>
+
+	<pluginRepositories>
+		<pluginRepository>
+			<id>apache-snapshot</id>
+			<url>https://repository.apache.org/content/repositories/snapshots/</url>
+		</pluginRepository>
+		<pluginRepository>
+			<id>maven-central</id>
+			<url>http://repo1.maven.org/maven2/</url>
+		</pluginRepository>
+	</pluginRepositories>
+</project>

File src/main/java/com/hascode/tutorial/TimerExampleEJB.java

+package com.hascode.tutorial;
+
+import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.Schedule;
+import javax.ejb.Stateless;
+
+@Stateless
+public class TimerExampleEJB {
+	private final Logger log = Logger
+			.getLogger(TimerExampleEJB.class.getName());
+
+	@Schedule(minute = "*/1", hour = "*")
+	public void runEveryMinute() {
+		log.log(Level.INFO,
+				"running every minute .. now it's: " + new Date().toString());
+	}
+}