Category Archives: java

Simple easymock example

EasyMock can mock an interface, or class. In this way, we can test our code without implementing them. In order to use the static functions in easyMock, we can either extend it, or use “import static” key word. I think using “import static” key word is more general. Let’s start review the code. main/java — foo.bar.MyInterface… Read More »

Add maven to project

After create a dynanic website, we hope to automatically add jar files by maven. How to turn on the maven feature? And go to the project directory, and run the following command: mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false It’s done! Refer: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

log4j

log4j.properties log4j.rootLogger=DEBUG, file, stdout # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=soap3.log log4j.appender.file.MaxFileSize=10MB log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L – %m%n # Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L – %m%n log4j.xml <?xml version=”1.0″ encoding=”UTF-8″ ?> <!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”> <log4j:configuration debug=”true”> <appender name=”console” class=”org.apache.log4j.ConsoleAppender”> <layout class=”org.apache.log4j.PatternLayout”> <param… Read More »

Read Spring Batch parameter to bean

After we add parameters to a job and run it. How do we get the parameter in the class? In config.xml, we add the following code: <bean id=”beanName” class=”com.pli.project.sba”> <property name=”emailFlag” value=”#{jobParameters[FAILURE_EMAIL]}”/> <bean> <bean class=”org.springframework.batch.core.scope.StepScope” />

Set command line parameters in Intellij

package com.pli.project.test; /** * Created by lipeng on 2015/4/4. */ public class App { public static void main(String[] args) { boolean eFlag = false; boolean fFlag = false; for(String para : args){ if(para.equals(“-e”)){ eFlag = true; } else if(para.equals(“-f”)){ fFlag = true; } } if(eFlag){ System.out.println(“with -e parameter”); } if(fFlag){ System.out.println(“with -f parameter”); } }… Read More »

Run class in jar file

Suppose we have below structured maven project. After we build it by maven, it generates test-1.0.jar file in target folder. How do we run this App.class in jar? We can run it by below command: java -cp test-1.0.jar com.pli.project.test.App In another case, if there are more than one jar file needed, we can specify more… Read More »

Spring Batch run by Spring Batch Admin

The second way to run Spring Batch job is by Spring Batch Admin. It is more powerful. By SBA, we can execute/stop/monitor our batch job in web UI. I downloaded the SBA sample code from Spring Batch website and made it more simple version. I used the mysql to store the metadata. The metadata tables… Read More »

Spring Batch run by Console

There are two ways to run your batch job. First is to use console command. In order to do this, we need to compile the batch job, and saves all dependency jar in a lib file. We just write the following in the maven pom.xml(I refered this good example from mkyong.) <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution>… Read More »

Spring Batch Basic

In last 2 weeks, I spent a lot of effort in researching in Spring Batch. This framework requires a lot of xml configuration. Below, I attached y passed code and explanation. My Spring Batch project refers from mkyong. database.xml If we want to autimatically create the metadata in database, we should add <jdbc:initialize-database> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:jdbc=”http://www.springframework.org/schema/jdbc”… Read More »

Explanation for pom.xml

<project> <modelVersion>4.0.0</modelVersion> <!–shows pom.xml structure complies with 4.0.0 version. Normally, it is 4.0.0> <groupId>mvn.myapp.com</groupId>  <!–where the project locate>  <artifactId>MavenTestApp</artifactId>  <!–project name> <packaging>jar</packaging>  <!– the form of the compiled result, normally, it can be jar, war and ear.> <version>1.0-SNAPSHOT</version>  <!– version of the project, SNAPSHOT means it is still under development> <name>Maven Quick Start</name>   <!–name of… Read More »