[IDEA & amp; Eclipse] 2. How to migrate from Eclipse to IntelliJ IDEA: intellijidea

Source: Internet
Author: User

[IDEA & Eclipse] 2. How to migrate from Eclipse to IntelliJ IDEA: intellijidea

I used IntelliJ IDEA for a long time. After using it, I thought it was really useful. Many people who have just switched over from Eclipse may not be able to adapt to it. I will share some experiences and common functions in the use process, of course, before reading this article, we recommend that you first read the features automatically completed by 20 IntelliJ IDEA codes. This article introduces the features automatically completed, the shortcut key description can be improved to take care of children's shoes with inconsistent key positions by default. This article describes the shortcut keys based on the default keymap of Mac OSX 10.5 +. Of course, it also provides relevant text instructions, if it is inconsistent with my binding, you can directly search in keymap.

Display row number in basic settings

This was a very simple issue in Eclipse. Some people have asked this question after moving to IntelliJ. After setting the file in the same way, we found that it only takes effect for the current file. Opening another file still has no row number. You just execute commands in vim.set numberInstead of setting the same effect in. vimrc. You need to set this option in IDE Settings. Select this option. For other Settings, you can select this option, such as displaying spaces.

File and Navigation Association

When we often need to open a file when writing code, we want to automatically open the link to the location in the file tree on the left, this makes it easy to find other files or other related files in this directory. In fact, IntelliJ provides several solutions. The first solution is the same as Eclipse, as shown below:

  • In the past, the setting in Eclipse was also very simple, but IntelliJ was a little different. If you want to temporarily open the file, click on the small Earth (at first glance, it looks like a small globe) icon. If you want to make it all the same as the one in Eclipse, you can see two options in the floating layer.AutoScroll to SourceAndAutoScroll from sourceIntelliJ is very user-friendly and divided into two settings. If both of you select this option, the basic and Eclipse functions are completely consistent, but you can simply select one.

Another way is to useNavigation BarIntelliJ can be keyboard-based for many operations. This is a required feature for people who like keyboard-based operations. The operation mode is to use shortcuts when opening files.⌘+UP (Jump to Navigation Bar)Then a drop-down will appear, which is basically the list of files in the directory where the file is located. You can also useUpper/lower right key positionIs it cool to select other directories?

Note:We recommend that you setView > Navigation BarClick the option, so that the shortcut key will appear at your mouse position and you will feel more input. Of course, you will basically lose the right to use the mouse, this requires you to use it according to your personal interests.

Shortcut Key Usage

If you are an Apple computer user, it is recommended that you change it to Mac OSX 10.5 + key binding, because the Mac OSX 10.5 compatible Windows version of the key is really bad, it is really uncomfortable to use, like your default habits⌘+wIs to close the tag. In this key binding, it is actually a shortcut key for selecting text based on the symbol.

Here we will mainly introduce several commonly used shortcut keys, or you may not know some shortcut keys in IntelliJ. You can refer to the Keymap on the official website to introduce Getting Started. It is important to learn the shortcut keys required for querying by yourself in Keymap. Do not open that useless Baidu every time. For details, refer to the link provided at the end of this article.

Call out Outline

One of the many shortcuts used in Eclipse in the past isctrl+oIn this way, all the member variables and methods of the code file can be called up, and it is very convenient to support searching. IntelliJ is a basic function, which is frequently asked by new users, the shortcut in intellij is⌘+F12 (File Structure). If you do not bind the Mac OSX 10.5 + key, the content in parentheses is what you can search for in Keymap.

Basic operations
  • Copy the entire row or block:Use in Eclipsectrl+alt+Up, IntelliJ default is⌘+D (Duplicate Line or Block)In fact, there is a gap between this and Eclipse, especially when multiple lines or content is selected, you can try it if you don't believe it. So you canDuplicate LinesDefine the previous shortcut key. What I define isOption+DThis key position does not have any shortcut keys in my default binding. You can bind one by yourself.
  • Select text by symbol:This key bit is used too much and is also very useful. For example, there is such a line of code<name>SpringSource Milestones Proxy</name>You place the cursor in a certain position in the Milestones, you want to replaceSpringSource Milestones ProxyIt is another word. If you want to replace itTest XXIn fact, you only needOption+Up (Select Word at Caret)You can select the words you want. When you want to develop, you will find that there are too many keys, I am not used to changing to other editors or IDE without this key position.
  • Delete the entire row:You can directly⌘+delete (Delete Line)Alternatively, you can use IntelliJ's smart function to cut the text when you select this line.`⌘+xThe entire line is automatically cut according to the selected text, but if you do not have any selected text in the row, it is similar to a shortcut key to delete the row, however, this is actually poor. We recommend that you use⌘+delete.
  • How to directly jump to the interface: Cursor + option + mouse clickOr⌘+option+B.
  • The statement automatically completes Statements completion:This has been explained in the features of the 20 automatically completed codes of IntelliJ IDEA. Here we will focus on it, because it is really useful and strongly recommended.Intelligent Automatic completion of ctrl + shift + SpaceWhen there are too many prompts, this key will surprise you.
  • Jump between the same words:In Eclipse, the shortcut key isctrl+kThis function is quite useful. It is not missing in IntelliJ, but it is blank by default in Mac OSX 10.5 + key binding. It is said that Windows is bound by default. You can query it and I have bound⌘+ctrl+k (Find Word at Caret), You do not need to bind one, and then you can combine other key locations to implement the previous⌘+G (Find Next)Next⌘+Shift+G (Find Previous)Is very practical.
Version Control settings

We certainly have version control in our development. When the local files and version libraries are inconsistent in the previous Eclipse, a file and Its folder will appear.〉It means that you can easily see which local files have been modified, but this is not allowed by default in IntelliJ. It only provides a color change for the changed file during modification, excluding the parent folders of the file. If you want to change the color, you need to check the settings.
In fact, you can understand the English explanation. If this function is enabled by default, you can directly adjust the display color of the folder.Settings > Editor > Colors & Fonts > File Status.

Non-English display of Java resource files

In terms of Resource files, IntelliJ idea is also better than Eclipse. It is quite convenient to modify an attribute in the Resource Bundle mode. You can modify attributes of all languages on the same operation interface, all of this is done automatically, as shown in:

There is also an intimate sorting and grouping function, especially this sorting.

There is also a problem in the default settings, that is, the Chinese character will be displayed as the Unicode code by default. In fact, select a setting (Settings > File Encodings), For example:

In this way, all Unicode display can be automatically converted to the language in which it should be displayed.

How to better run a Maven-compliant web project

I remember that at the time when I first started using Eclipse, the Java EE Project was not supported by default. I had to use a plug-in named MyEclipse. Today, it seems that someone else is using this plug-in, in that year, after each Web project was modified, it had to be Deploy and the modification was executed, which was very painful. Later, I used the Tomcat plug-in by myself. This ensures that the jsp and static files can be directly executed without the need for Deploy, because the Tomcat directory directs directly to your project file, it is indeed a lot easier.

In IntelliJ, if you are using a traditional Java EE structure (src and webMoudle are under the root directory), add a Tomcat directly in the Run invocations, click the + sign to add it (of course, note that even if there is no search box, you will automatically filter the results after entering the characters). In this way, you need to Make the Project, that is, to modify the Java file during running.⌘+F9 (Make Project). However, if you are in compliance with the maven Project structure, it is not ideal to continue this configuration. Each time you modify the jsp file, Make Project is required, since IntelliJ idea will automatically give you DeployMent after each Make Project, it seems like returning to the very troublesome environment a few years ago.

This problem is actually easy to solve, that is, do not run your web project in this way. Since maven-compliant projects are naturally built using maven or gradle, you need to use the jetty plug-in of maven to run the project, such as Configuration:

Of course, you can also click "run" to automatically add one:


You can also use the tomcat6 or tomcat7 plug-ins to run jetty.

How to import and run Eclipse web Structure Projects

In view of the fact that some users have not yet transformed Maven to build projects, of course I would like to say with my heart that the building should be a quick start. if you do not want to change it, you will also come out of this chapter separately, and some operations are still quite troublesome. Here we will also talk about it. Let's go one by one. There are two choices during import, and I will explain it in two parts. ClickFile > Import Project…Select your project directory and click OK, for example:

Use new project to import

In this way, as shown in the figure, the import process is basically completed by the next step. However, for the first time, you can also pay attention to what you have done in each step, for example, you can analyze some jar files. If you use Spring, you can analyze all your configuration files. After the final completion, the project starts to build the index. After everything is ready, we can complete the basic configuration, because it is a web project that can basically run on servers such as Tomcat, it is basically successful. Main points:

  • Handle the dependency, because maven is not used, so you have to work on your own.
  • Set the compiling path of the java file, if needed
  • Add your Tomcat and run successfully
Dependency

OpenFile > Project StructureIn this section, we mainly use the following red parts:
Let's take a look at the main components:

  • SDKs:It mainly stores our JDK, such as (I download the JDK with source, so that you can directly view the JDK-related Java source code ):
  • Global Libraries:It is mainly a public jar file. For example, several servlets in the servlet may be required for each project, but the Eclipse variable is not easy to use here. Therefore, you need to use this configuration, as shown in reference:
  • Facets:We will not introduce it here. We will add it later if necessary.
  • Libraries:This is basically the project library, not global. Imported projects usually include your Eclipse. All dependencies in classpath are exported as a lib library and then applied to your project module.
  • Modules:This basically includes the project module. Generally, the Eclipse project structure is a single module.

The configuration we need to do is mainly in Modules, and the other several can be configured as needed.

After completing these steps, clickRun > Edit ConfigurationsClick+And then select ** Tomcat> Local Server **. These steps are similar to those of Eclipse. Select the corresponding path and so on. You only need to pay attention to this. You need to add a DeployMent, for example:

If the number + in DeployMent in the Windows Image isIn the dialog box that appears, select a folder and select the default webMoudle folder of eclipse (MyEclipse is the WebRoot folder). You must not select this folder as the main folder of the project, otherwise, the operation fails.ctrl+RRun. Running in debug mode isctrl+D.

Use IntelliJ to import Eclipse Projects

The procedure is similar to the previous procedure, that is, the procedure is less than the previous step. If any problem occurs, refer to the previous chapter.

HQL query support

In the past, Eclipse had an HQL plug-in that can directly input the HQL syntax to check whether the test results are correct. You can also use IntelliJ, but no plug-ins are required to provide support by default, if the Hibernate support is not automatically added during project import, you need to add the support for Hibernate. Select the project and right-click the project, as shown in:

Click choose Hibernate. If no Hibernate is available, the project has automatically added support for Hibernate. After that, you can perform the following operations:

Select the above HQL icon, and enter the HQL you want to enter in the console. The same can be done automatically.

Notes

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.