Tag 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 »

Read json

I have following json file and folder structure. A maven dependency I need is following: <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> By following colde. I read the json file from it: package com.pli.project.test; import org.apache.commons.io.IOUtils; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import java.io.*; import java.util.HashMap; /** * Created by lipeng on 2015/4/4. */ public class App… 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 »