Skip to content

Instantly share code, notes, and snippets.

@lalyos
Created July 17, 2012 09:40
Show Gist options
  • Save lalyos/3128356 to your computer and use it in GitHub Desktop.
Save lalyos/3128356 to your computer and use it in GitHub Desktop.
JavaBasic - maven
package com.epam.junior;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
public class LunchTime {
private static final String PRESS_ENTER = "press.enter";
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm";
private static final String LUNCH_DATE = "lunch.date";
private static final String LUNCH_LOCALE = "lunch.locale";
private static final String WRONG_TYPE_MSG = "wrong.type.msg";
private static final String AFTER = "after";
private static final String BEFORE = "before";
private static final String LUNCH_TYPE = "lunch.type";
private static final String LUNCH_MSG = "lunch.msg";
static org.apache.log4j.Logger logger = Logger.getLogger(LunchTime.class);
static java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(LunchTime.class.getName());
static final long MINUTES_IN_MILLIS = 60000;
public void endlessMessageLoop() {
while (true) {
internalLoop();
}
}
private void internalLoop() {
try {
String locale = System.getProperty(LUNCH_LOCALE, "en");
ResourceBundle bundle = ResourceBundle.getBundle("messages", new Locale(locale));
org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger();
org.slf4j.bridge.SLF4JBridgeHandler.install();
Date now = new Date();
String dateS = System.getProperty(LUNCH_DATE, "2012-07-18 12:00");
String msgFormat = bundle.getString(LUNCH_MSG);
String type = System.getProperty(LUNCH_TYPE, BEFORE);
logger.info(dateS);
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
Date date = sdf.parse(dateS);
long nowF = now.getTime();
long dateF = date.getTime();
long result;
if (type.equals(BEFORE)) {
result = (dateF - nowF) / MINUTES_IN_MILLIS;
} else if (type.equals(AFTER)) {
result = (nowF - dateF) / MINUTES_IN_MILLIS;
} else {
logger.warn(bundle.getString(WRONG_TYPE_MSG));
return;
}
//System.out.println("itt jratam (haxor) ");
logger.info(MessageFormat.format(msgFormat, result));
System.out.println(bundle.getString(PRESS_ENTER));
System.in.read();
} catch (Exception e) {
logger.error(e);
}
}
public static void main(String[] args) {
LunchTime lunch = new LunchTime();
lunch.endlessMessageLoop();
}
}
<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.epam.junior</groupId>
<artifactId>lunchtime</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>lunchtime</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<systemProperties>
<systemProperty>
<key>lunch.msg</key>
<value>pom.xml message</value>
</systemProperty>
</systemProperties>
<mainClass>com.epam.junior.LunchTime</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.epam.junior.LunchTime</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<configuration>
<finalName>uber-${artifactId}-${version}</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment