Let's make a LAN communication application Part 1 New project creation using Maven and Java entry point

Well, development started like this.

This time, a text transmission / reception application used in the LAN.

I'd like to say design ... but is it okay to just use a rough use case this time?

Communication is socket communication, and there are many samples. It's okay Somehow (positive)

This time, the language will be Java and the communication will be TCP / IP. I will use Eclipse Oxigen 4.7.3a as the environment. The guy who left it alone after putting it in the PC. The reference port is ... well, let's decide by rolling the dice appropriately.

Creating a new Java Project

I thought, but it was my first time to develop scratches for Java programs. Well, any language has a slightly different habit, and if you find out what to do, it will work.

When I thought about it, I immediately found something to investigate. Somehow, "when creating a Java program, it is common to create a project using Maven". Eclipse is also included, you. Maven, I've heard of it, isn't it?

That's why I investigated quickly

What is Maven

Reference: Wikipedia -Maven

Maven seems to be a project management tool for Java. I've heard that it was certainly named alongside Redmine as a project management tool. I didn't know it was the successor to Apache Ant. I mean, Ant is just the image I used for the build.

Apparently the image is not completely different, Build tool, library management tool, Java project development template, test tool, and so on. It seems like an integrated development support tool packed with various functions. (Specialized in Java)

Personally, I'm really worried that it's easy to work with Jenkins. I'll look it up later.

I understand the outline, so create a new one ...

Now that I know it roughly, let's check it each time. First, create a new project using Maven ...

When I thought about it, I decided to select the archetype. Maven archtype ... Is it like a template? Continue the investigation while thinking.

Apparently the idea itself is not wrong. Cheeks. Which one should I choose this time? (Edokko)

・ ・ ・

・ ・ ・

・ ・ ・ ・ ・ ・

that? I can't find an explanation of archetypes in Japanese.

So I've seen it in Apache, the developer of maven. The following is a Japanese translation that smells like humor. For those who want to refer to the text, here (English)

Group ID Artifact ID Description
org.apache.maven.archtypes maven-archetype-archetype archetype Generates a sample archetype
org.apache.maven.archtypes maven-archetype-j2ee-simple Generate a simplified J2EE (enterprise) sample archetype
org.apache.maven.archtypes maven-archetype-mojo Generate an archetype for the Maven plugin sample
org.apache.maven.archtypes maven-archetype-plugin Generate an archetype for the Maven plugin
org.apache.maven.archtypes maven-archetype-plugin-site Generate an archetype for the Maven plugin site
org.apache.maven.archtypes maven-archetype-portlet JSR-Generate an archetype for 268 standard portlet samples
org.apache.maven.archtypes maven-archetype-quickstart Generate an archetype for the Maven project sample
org.apache.maven.archtypes maven-archetype-simple Generate a simple Maven project archetype
org.apache.maven.archtypes maven-archetype-site Supports formats such as APT, XDoc, FML and i18n your site(Multilingual)I'll generate an archetype that demonstrates how to do it
org.apache.maven.archtypes maven-archetype-site-simple Generate an archetype for Maven site samples
org.apache.maven.archtypes maven-archetype-webapp Generate an archetype for the Maven web app sample

HM. I feel that there are a lot of things for the Web. It seems to be interesting, so I will think about it in the future, this time I chose maven-archetype-simple When I thought about it, it wasn't initially registered in Eclipse. There is no help for it, so select maven-quick start. It's an application that runs on a machine. You may think about it because the server is in your house.

Once made, this time

So I made it Suddenly there is an error.

2018y06m11d_232932824.jpg Project configuration is not up-to-date with pom.xml. Select: Maven->Update Project... from the project context menu or use Quick Fix.

Troubleshooting Maven Error: Project configuration is not up-to-date

When I looked it up, it said, "It will come out when the setting changes etc. are not reflected." Where do you mean when you say "Select: Maven-> Update Project ... from the project context menu or use Quick Fix."

Is the setting of the entire project the root of the project? When I open the context menu, I see an item like that. Select [Project root context menu (right-click)]-[Maven]-[update Project] to display this screen. (Since the shortcut key was set to Alt + F5, impatient is GO with the shortcut key!)

2018y06m11d_233748877.jpg

If you press OK here, the update was successful.

Warning will come to you without any time to breathe. Somehow the build path doesn't pass.

2018y06m11d_233946076.jpg Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.

Troubleshooting Maven warning: build path specifies execution environment

Apparently the problem is that jre1.5 is specified. The default setting for Maven is jre1.5. By the way, I used jre1.8

[JRE System Library context menu (right-click)]-[Properties]-[System library] settings I was able to safely remove the warning by setting "Workspace default JRE (jre1.8.0_171)".

2018y06m11d_235447310.jpg

Although I was able to turn off the warning, in the current state, the warning is displayed again when I can write a project update. This is a little unpleasant, so I decided to investigate other methods.

The point is that you should write the Java version to be used in the configuration file: pom.xml.

After investigating, it seems that the following two descriptions should be added to the properties item of pom.xml together with the JRE version. Official here

Element Description
maven.compiler.source The value set in the source argument of the Java compiler. String type
maven.compiler.target The value set in the target argument of the Java compiler. String type

Probably the equivalent of javac's -source and -target options. (I thought that javac was specified in the official compilerId.) By the way, although it is written in the official value of the item, the default is 1.5.

That's why the change procedure

How to change from OverView in Eclipse

  1. Double-click pom.xml from Project Explorer to display OverView. 2018y06m12d_012406231.jpg

  2. Click [Properties]-[Create] to call up the input dialog. 2018y06m12d_012758918.jpg

  3. Set the Element name (corresponding to maven.compiler.source) in the Name field and the value in the Value field.

  4. Confirm that it has been reflected. 2018y06m12d_015329080.jpg

By the way, with Eclipse Oxigen 4.7.3a that I use, it was handmade without any auto-complete function.

How to modify the xml file directly

  1. Double-click pom.xml from Project Explorer to display OverView. 2018y06m12d_012406231.jpg

  2. Click the [pom.xml] tab at the bottom of the window to switch the display. 2018y06m12d_010813521.jpg

  3. Find the properties block and add the maven.compiler.source and maven.compiler.target elements. 2018y06m12d_015923512.jpg

To be honest, I feel that it is okay to rewrite directly in the current state.

Although the environment construction is over, what is the entry point?

All you have to do is make it! ・ ・ ・ But I was curious, so I did a little research. Is it okay to use main () as the entry point for Java applications? Aside from main (), how do you set up a class?

I thought, so I did an additional survey.

If you look it up, there is no doubt that the entry point is main (). However, there is no description on how to specify the class.

Most of the time this is in the project properties! Display the properties of the project root with Atari. You can open the setting screen of the application by pressing [Run / Debug Setting]-[Edit].

2018y06m12d_022410249.jpg When you press the [Edit] button on the right side of the screen ...

2018y06m12d_022517590.jpg Transit to the detailed setting screen.

So, it seems that the Main class here specifies the holding class of the entry point. So let's create another main method and experiment.

2018y06m12d_023103090.jpg

For App, Ppa The main () that existed in the app was Hello World, so I changed the message. Goodbye is lonely so take a break.

So, change the setting of the matter and execute

I was able to change the entry point safely. 2018y06m12d_023344212.jpg

Although it is not supposed to write multiple main methods Aside from the Run / Debug Settings and Edit, I'm curious that there was a New button and a Duplicate button. If you think about it, it seems that you can save multiple startup conditions here, so I will omit it.

Where is the substance of the setting? I searched a lot, but I couldn't find it. When I thought, there was a description in here. Apparently there is a manifest similar to android.

I was really curious, so I continued the investigation. META-INF / MANIFEST.MF exists in the jar that puts the compiled .class files together, and I should set it in the Main-Class element there. Reference: Introduction to Java in Tohoho, * Item for creating a jar file *


We are planning to start production from tomorrow. Today's working time is 05:15:44.

Recommended Posts

Let's make a LAN communication application Part 1 New project creation using Maven and Java entry point
Let's make a communication application in LAN Part 2 Display a window using JavaFX / Wait for socket reception
Let's make a communication application in LAN Part 4 Set information in JavaFX control / Call JavaFX screen from thread
Install java and maven using brew on new mac
Let's make a calculator application in Java ~ Display the application window
Socket communication with a web browser using Java and JavaScript ②
Socket communication with a web browser using Java and JavaScript ①
Make a rhombus using Java
Let's make a book management web application with Spring Boot part1
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Create a Java project using Eclipse
How to make a Maven project
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
Java beginner tried to make a simple web application using Spring Boot
I tried to make a talk application in Java using AI "A3RT"
Let's make an intra-LAN communication application Part 3 Create a JavaFX event handler / Create a message transmission / reception function by socket communication
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
[Java] Let's make a DB access library!
Let's make a calculator application with Java ~ Create a display area in the window