Use idea + Maven + Git to quickly develop Java or Web applications (GO)

Source: Internet
Author: User

0-0 Prefacerecently, I've been doing reptiles with my colleaguesone of the main problems I encountered was: my colleague put a crawler on GitHub to download it myself, and then I can set up the environment to get the whole project running to catch 51job looking for work data. To clone a project down on Git, the project is to manage various plug-in jar packages through Maven, and I'm groping myself to get the environment running. (1) Web content crawling with python2.7 to do, crawl the main use of the library has: beautifulsoup4-4.5.1,lxml-3.6.0,stomp.py-4.1.9, can go to the official website to download after decompression, in the decompression directory run steup.py files can be. (2) Message Queuing middleware with apache-activemq-5.9.1, download and unzip run Bin\win64\activemq.bat, open a message queue MQ(3) One of the Java processing parts with IntelliJ idea IDE, after the import found that each dependency is not automatically downloaded. Intellij idea IDE How to import Maven project, choose File--open--projectname, open the project, find a variety of dependency packages are not, need me one to find and then download, and then put in the local self-installed MAVEN project, Depending on the package too much, can not find it, only to re-find ways. The trick is to import a MAVEN project into IntellijIDAE2016.2,The key point is to choose open--"Pom.xml, will automatically download and import the dependency package file, instead of manually go to the one to find." Super convenient. You need to configure Pom.xml if you choose to import the project name

0. Introduction

Today I would like to share with you my main Java development tools, which I usually work with: writing code with idea, using Maven to manage jar dependencies and project packaging, and Git for code versioning.

About the installation and configuration of the three tools of the process, this article does not explain, there are not quite clear friends, can give me a message, I will try to answer.

The following is an example of developing a Smart application that describes how these three tools are used.

1. Use Git to download the source code

First, find a separate folder on your disk to store all of the Smart project source code, for example: D:\Project\smart, the following is called "Working directory."

Then, download the smart Framework and smart Sample source code to the local disk, respectively, via the git clone command. As follows:

    1. Smart Framwork:http://git.oschina.net/huangyong/smart-framework
    2. Smart Sample:http://git.oschina.net/huangyong/smart-sample
    3. Smart Cache:http://git.oschina.net/huangyong/smart-plugin-cache

For example: Use the git clone http://git.oschina.net/huangyong/smart-framework command to download the Smart Framework Project source code.

After executing the above three git clone commands, you should see these three subdirectories in your working directory: smart-framework, Smart-sample, Smart-plugin-cache.

2. Writing the Maven project configuration file

At this point, you can write a Maven project configuration file (as a root profile) in the working directory (that is, the siblings of the three project directories above), and you will also need to name pom.xml to organize the three projects. The code is as follows:

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupId>Smart</groupId>    <Artifactid>Smart</Artifactid>    <version>1.0</version>    <Packaging>Pom</Packaging>    <Modules>        <Module>Smart-framework</Module>        <Module>Smart-sample</Module>        <Module>Smart-plugin-cache</Module>    </Modules></Project>

3. Open Maven Project directly with idea

Open your idea and select Open Project, and a dialog box will appear:

Navigate to your working directory in the Address bar (you can manually write the path or paste the path directly), select Pom.xml, and then idea will automatically create a Maven-based project.

Note: In the Idea's wizard interface, be sure to choose Open Project instead of Create New project. You can also import a Maven project using import project, but not directly Open project.

Your fingertips, the project has been created!

4. Compiling the source code

To compile it, you can click this button in the toolbar:

You can also use the shortcut key Ctrl + F9 to show off your major.

Then, idea will compile the entire project source code, generally there is no news, because no news is good news.

In addition, you can use Maven to compile. Click on the Maven Projects tab on the right side of idea to see the following interface:

Note: Smart (root) represents the root configuration of maven, the pom.xml you have just written, and it manages all other MAVEN projects.

You can double-click the Compile node, and then idea will call Maven to compile. This way you do not need to manually enter the Maven command in CMD, of course, other commands you can also double-click to run.

5. Configuring Tomcat in Idea

Note: It is recommended to use Tomcat 7.0+

To configure Tomcat in idea, just a few steps:

First, click the drop-down box in the toolbar and click the Edit Configurations menu item in the drop-down menu.

When clicked, a dialog box pops up and you can click the "+" button in the upper left corner to create a new Local Tomcat Server.

You can then name Tomcat, which is Unnamed by default and can be modified to Tomcat. In addition, if you do not want idea to automatically open the browser, remove the Start browser check box, I usually do this.

Then, to deploy a project, you need to switch to the Deployment tab in, for a simple configuration.

To do this: click the "+" button, click Artifacts., select Smart-sample:war exploded, and modify application context to "/smart-sample".

Finally, it is recommended that you switch back to the Server tab and select Update resources under the on frame deactivation drop-down box.

This is done to automatically update resources (including HTML, CSS, JS, JSP, etc.) when you switch out idea, and use the third option if you need to automatically compile.

Note: Idea 12.1.6 (the latest version) has a Bug, the second item is also automatically compiled, in the previous version does not exist, do not know whether the next version will solve the problem, but this problem will not affect your use.

Click the OK button to complete all of Tomcat's configuration, and now you can see the Tomcat icon in the toolbar.

Tip: Before you run, you must create the database manually. For example, the database script for Smart Sample is in the doc directory of Smart-sample.

6. Running the application in Debug mode

You can simply click the Debug button in the toolbar to run the Smart Sample in debug mode.

Recommendation: Use debug mode as much as possible during the development process, so you can break points in idea at any time to debug. In addition, it is important to note that the debug function of idea is very powerful and very useful!

7. Commit and update Git in idea

The toolbar also includes Git's common operations, which are easy to use.

Indicate by tag: Update code, submit code, view differences, view history, undo changes.

In addition, you can click the Changes tab at the bottom to view local changes and commit logs (log).

You can select a version to view the file content of the specific submission, you can also select multiple versions to view together, there are many useful features.

8. Summary

Idea is a very good Java integrated development environment, very simple to use and very fast to get started. It has plug-in support for mainstream technologies and tools, and you can customize the plugin list to disable plugins that are useless to you.

Maven is a great project builder, and with it, you don't have to manage a whole bunch of jar packages in each project, and it's also very helpful to package (Jar/war) the project, but it's not just that.

Git is a very good version of the Code control system, it can effectively achieve multi-person office, in addition, you can submit code to the local repository, and then submit to the remote repository one time.

The combination of the above three tools will greatly improve the ability of Java programmers to fight! In this, we strongly recommend that you use!

Use idea + Maven + Git to quickly develop Java or Web applications (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.