Easy library introduction with Maven!

Purpose

It is very convenient to prepare a library and build an environment with Maven for development! The procedure is listed below.

download

Download Eclipse or pleiades. There are many commentary sites about this, so I will omit it.

procedure

First, start Eclipse image001.png

File-> New-> Create Maven Project image002.png

Check to create a simple project image003.png

image005.png

Now that the project is created We will continue to add libraries with Maven!

Library added with Maven

Open pom.xml of the created project image006.png

Open "Dependencies" in the center tab and click "Add" in the middle image007.png

Then, a screen for entering the information of the library you want to add appears. image008.png

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 image009.png

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. image010.png

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. image011.png

When you enter, return, and save Maven dependency is increasing and you can see that there is a jar file image012.png

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 image013.png

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! image014.png

With Maven, you can easily add a library like this!

Recommended Posts

Easy library introduction with Maven!
Groovy super easy introduction
Easy BDD with (Java) Spectrum?
Try gRPC with Java, Maven
Easy web scraping with Jsoup
[Introduction] Build MVC with Scala
[For super beginners] Maven super introduction
Introduction of library ff4j that realizes FeatureToggle with Spring Boot
Easy JDBC calls with Commons DbUtils
100% Pure Java BDD with JGiven (Introduction)
Introduction to algorithms with java-Shakutori method
Easy input check with Bean Validation!
Easy Pub/Sub messaging with Apache Kafka
Create command line app with maven
Server processing with Java (Introduction part.1)
Hello World with GWT 2.8.2 and Maven
Easy database access with Java Sql2o
Create a Maven project with a command