It is very convenient to prepare a library and build an environment with Maven for development! The procedure is listed below.
Download Eclipse or pleiades. There are many commentary sites about this, so I will omit it.
First, start Eclipse
File-> New-> Create Maven Project
Check to create a simple project
Now that the project is created We will continue to add libraries with Maven!
Open pom.xml of the created project
Open "Dependencies" in the center tab and click "Add" in the middle
Then, a screen for entering the information of the library you want to add appears.
Let's add the Jsonic library here http://jsonic.osdn.jp/index.html#maven
If every library has a Maven repository, there is a description like the following, so enter each one.
<groupId>net.arnx</groupId>
<artifactId>jsonic</artifactId>
Enter the version if you want to include a specific version
Now click OK and go back to the previous screen and the dependency will be added If you save pom.xml in this state, the library will be added.
However, if the version is not entered, it may not be downloaded. In that case, select the property of the one added in the dependency and enter the version.
When you enter, return, and save Maven dependency is increasing and you can see that there is a jar file
The rest is the same as a normal library Can be used as it is
Create a suitable source like this After launching the Maven project, I just edited pom.xml Jsonic has been imported
Testjson.java
package maventest;
import java.util.HashMap;
import net.arnx.jsonic.JSON;
public class Testjson {
public static void main(String[] args) {
HashMap<String, String> testdata = new HashMap<String, String>();
testdata.put("testkey1", "testvalue1");
testdata.put("testkey2", "testvalue2");
String jsontext = JSON.encode(testdata);
System.out.println(jsontext);
}
}
When you run the source as a Java application For console-like output!
With Maven, you can easily add a library like this!
Recommended Posts