Transfer from eclipse to IntelliJ idea a little bit of experience

Source: Internet
Author: User

I use IntelliJ idea is not too long, after using this period of time, I feel really good. A lot of people who just turned around from eclipse may not be able to adapt, I would like to use some of the experience and common functions to share, of course, before reading this recommended you first read IntelliJ idea of the 20 code automatically completed features, this article on the characteristics of the automatic completion of the introduction is very good, Only the shortcut key description can be more complete, you can take care of the default binding keys inconsistent children's shoes. This article describes the shortcut key is based on the Mac OS X 10.5+ default Keymap, of course, will also provide relevant text description, if and my binding can go directly to the Keymap search. Basic Settings Show Line Numbers

This was a simple question previously in eclipse, and some people who moved to IntelliJ later asked the question. The same way you set up the later discovery only works on the current file, and there is still no line number to open another file. It's like you're just executing a command set number in Vim instead of setting the same effect in. vimrc. This needs to be set in the IDE settings, as shown in the illustration: Other settings can be checked by reference to this setting, such as displaying spaces, and so on. file and navigation associations

When we write code, we often need to open a file, want to automatically open the link to the location on the left file tree, so it is convenient to find other files in this directory or other related files, in fact, this INTELLIJ provides several solutions, the first is the same way as Eclipse , as follows: Previously in Eclipse Setup is also very simple, but a little bit different in the IntelliJ, if you want to temporarily, open the file when you click on the small Earth (like a small globe at first glance) if you want to be like the one in Eclipse, Let this happen automatically, then you can see two options in the floating layer of the above figure AutoScroll to source and AutoScroll from Source,intellij very humanized two settings in the inside, All two of you are checked is basically and Eclipse's function is maintained completely consistent, just tick a natural also can.

There is another way is to use the IntelliJ provided navigation Bar, IntelliJ Many functional operations can be keyboard, this is like the keyboard operation of the necessary features, the operation is to open the file, the use of shortcut keys ⌘+up ( Jump to Navigation Bar), then there will be a drop down, basically is the file in the directory of the file list, can also use the top and bottom of the key to choose a different directory, is not cool.

Note: the option to view > navigation bar is suggested here, so that the shortcut key will appear in your mouse position, you will feel more input, of course, you will basically lose the right to use the mouse, this requires you to use according to personal habits. shortcut keys use

If you are an Apple user, it is recommended that you change to Mac OS X 10.5+, because Mac OS 10.5, the Windows compliant version of the keys, is so lame that it's hard to use, like your default custom ⌘+w is to turn off the label, In this key binding is actually a shortcut to select text based on the symbol.

Here are a few of the main introduction may be commonly used, or you may not know IntelliJ some of the shortcut keys, particularly commonly used you directly refer to the official website of the Keymap introduction getting started on it. Learn to Keymap in their own query needs of the shortcut key is the main, not every time you open that useless Baidu, you can refer to the end of this article to give the link. outline, pull up.

One of the many shortcuts used in Eclipse is ctrl+o, which can bring up all the member variables and methods of the code file, and it is convenient to support the search, IntelliJ this basic function is naturally, novice's words also often ask, this in the Intellj shortcut key is ⌘ +F12 (File Structure). If you're not a Mac OS X 10.5+, the content in parentheses is what you can search for in Keymap.Basic Operations To copy an entire row or block:Using Ctrl+alt+up,intellij in Eclipse by default is ⌘+d (Duplicate line or block), in fact, there is a gap between this and eclipse, especially when multiple lines or selected content, you can try. So you can define a shortcut on the duplicate lines in Keymap, and I'm defining option+d, which doesn't have any shortcuts in my default bindings, and you can try to bind it yourself.Select text by symbol:This one is used too much, and it is very useful, for example, there is a line of code <name>springsource milestones proxy</name> your cursor in milestones a certain position, You want to replace SpringSource milestones proxy for other words, the false idea is replaced with Test XX, in fact, you only need option+up (select Word at caret) two can select the word you want, when you want to in the development process , you will find that the keys are used too much, it is not used to change other editors or the IDE.To delete an entire line:You can direct ⌘+delete (delete line) or use IntelliJ intelligent function, cut the shortcut key, when the line is selected text cut ' ⌘+x will be selected text to achieve the cut, but you do not have any selected text in the bank will automatically cut the entire row, Then nature is similar to delete the line of the shortcut key, but this is still relatively lame, it is recommended to use ⌘+delete.to jump directly to the interface implementation method:⌘+option+ mouse click or ⌘+option+b.The statement automatically completes statements completion:This is explained in the IntelliJ idea's 20-code autocomplete feature, here or emphatically said, because it is very easy to use, also strongly recommended, but also the text of the intelligent automatic completion of ctrl+shift+space, when giving you a hint too much, this key will definitely surprise you.jump between same words:The shortcut keys in Eclipse are ctrl+k, which works well and is not missing in IntelliJ, but is null by default in the Mac OS X 10.5+ key bindings. It is said that there is a binding in the default bindings of Windows, you can query, I have bound a ⌘+ctrl+k (find Word at caret), no need to bind themselves, and then can combine other keys to implement the last ⌘+g (Find Next) Next ⌘+ Shift+g (Find Previous) function. It's very practical.version Control Settings

We certainly have version control of the development, when everyone before eclipse in the local file and version of the library inconsistent, then the file and the folder will appear a "said, you can easily see the local file modified which, but the default is not the IntelliJ." Just to change the file in the changes provided in the color changes, does not include its various parent folder Oh, if you want the same as eclipse, you need to check the following image set
In fact, read English interpretation can be understood, this default to open later if you want to adjust the folder display color directly to the settings > Editor > Colors & Fonts > File Status adjustment can be, You can adjust to the way you like it. Java resource files are displayed in a non-English language

IntelliJ in the case of resource files that personally feel like a triumph over eclipse, it is quite handy to modify a property in the resource bundle mode, and you can modify the properties of all languages on one interface, all automatically, as shown in the following illustration:

And also very intimate has a sort and grouping function, especially this sort.

The default setting also has a problem, that is, the Chinese default will be displayed as Unicode code, in fact, check a setting (Settings > File encodings) on it, the following figure:

This setting allows all Unicode display to automatically translate to the language it should display. How to better run a Web project that conforms to the MAVEN convention structure

Remember when you first started using Eclipse. The default is not to support the Java EE project, you must use a MyEclipse plug-in, until today as if someone is using this thing, when every Web project changes must be deploy, the modified things will be executed, It's very painful. Later on the use of their own Tomcat plug-ins, which can ensure that you modify the JSP and static files when you do not need to deploy directly can be executed, because the directory of Tomcat is directly pointing to your project file, so it is really a lot of worry.

In IntelliJ If you are a traditional Java EE structure (there is a src,webmoudle structure underneath the root directory), add a tomcat directly to the run configurations and click the + number to add it ( Of course you need to note that although no search box, you input characters will automatically give you filter results, so that when the runtime to modify the Java file will need to actively make project is ⌘+F9 (make project). However, if you are in line with the project structure of the MAVEN convention, it is not ideal to continue this configuration, and you need make project every time you modify the JSP file, because IntelliJ will automatically give you deployment every time you make project. It's like going back to a very troublesome environment a few years ago.

This problem is easy to solve, is not to use this way to run your Web project, since the MAVEN-compliant project is naturally using MAVEN or gradle This build tool, then you need to take advantage of Maven's jetty Plug-ins to run the project, you can configure the following figure :

Of course, you can also click the following figure directly to run will automatically add a:


See above figure actually also did not have to use jetty, use TOMCAT6 or TOMCAT7 plug-in operation also can. how Eclipse's web structure projects are imported and run

Since some users have not yet transformed Maven to build the project, of course, I would also like to say, Build this piece or turn it over. Because do not turn to also separate out this chapter, and some of the operation is still quite troublesome, the following will be said, or one by one to come, import when there are two choices then I divided into two parts, click File > Import Project ..., Then select your project directory, click OK, as shown below:

use new project to import

The first thing shown in this diagram is that the import is basically all the way next to completion, but the first time you can also pay attention to what each step does, for example, to help you analyze what the jar has, if you use spring and give you analysis of all your configuration files. The project starts to build the index after the final completion, and so we can complete the basic configuration after everything is ready, because the Web project is basically able to run on servers such as Tomcat on the basic success. Main points: deal with dependencies, because we're not using MAVEN, so you have to do your own thing. Set the compilation path for the Java file, add your tomcat if needed, and run a successful dependency

Open File > Project Structure, this section is mainly used to the following figure red parts:
Let's take a look at the main components: SDKs: The main storage of our JDK, and so on, the following figure (I download the JDK with source, so you can directly view JDK related Java source code): Global Libraries: A common jar file, such as a few jars of the servlet, may be required for every project, but Eclipse's variables are not working here, so you need to use this place to configure it, as shown in the following diagram: Facets: no introduction here, If you need to follow up add libraries: Here is basically the project library, not the global, the imported projects will generally put you in eclipse. All of the dependencies in Classpath are derived as a Lib library and then applied to your project's module Modules: This basically includes the project's module, which is typically a single module in the Eclipse's project structure.

We need to do the configuration mainly in the modules, the other several themselves according to the understanding of the configuration can be. Let's look at the Sourcesin Modules , as shown in the following figure:
All the source code of the project can be added, the figure shown in my project is actually less resource folder, so I select the resource and then click Sources can be, this will be in the left side of the source folders add a resource folder. Then is the paths section, this is the main class output path, the default is in the root directory out folder, if the project in the configuration file parsing and so on have written dead path, must strictly follow the Java EE specification, then need to modify this section as follows ( If this is not the case that I assumed, this step can be ignored:
Then the dependencies, the better configuration, add the need to rely on it.

Once these steps are complete, we can click on Run > Edit configurations, click the + number in the upper-left corner and select **tomcat > Local Server * *, which is similar to eclipse, Select the appropriate path, and so on, only need to pay attention to a point, you need to add a deployment, the following figure:

if the + number in the deployment in the Windows diagram is probably on the right , clicking on it will pop up the dialog box to select the folder and select the default Webmoudle folder for Eclipse (MyEclipse is the Webroot folder), This must not choose the wrong, do not select the main folder of the project, otherwise the operation will not succeed, and then Ctrl+r run. Running in debug mode is Ctrl+d. import projects with support for Eclipse projects using IntelliJ

The basic reference is similar to the previous one, that is, the step is less than the previous step, if there is a problem referring to the previous chapter. hql Query Support

Previous eclipse has a HQL plug-in can directly enter HQL syntax, query test results are correct, in IntelliJ you can also, but do not need any plug-ins to provide support by default, if you import the project without automatically adding hibernate support, That need to add hibernate support, mouse selected items, right-click the following image:

Click to select Hibernate, if no hibernate should be the project has been automatically added hibernate support. Then after the completion of the following figure can be manipulated:

Select the above hql icon, in the console input you want to enter the HQL can be, as can be automatically completed OH. Considerations IntelliJ for the file is saved at any time, basically do not need you ⌘+s (this key is the default is to save all), so you need to pay attention not to accidentally change a file, and then directly close the label, in fact, your unintentional operation has led to the modification of the file, May cause you to find a very strange error in the running of the project, I do not find that can turn off the automatic save settings, if you are not compulsive, the VIM plug-in may help you. The files in IntelliJ are synchronized with the local files in real time, so the Eclipse Refresh feature is not asked, because there is no need for that functionality at all. Some editors will remind you whether or not to update the local files, this is also the default does not give any reminders, as long as you modify, here will automatically sync update files immediately. Under the main menu file, there is a strange power Save mode, which also shows that, as the name suggests, it is a province-saving model. When you check this mode, IntelliJ does not give you any AutoComplete functionality, for example, if you enter a character will automatically prompt, after the check is gone, if this problem can be considered if you have a hand is not the point of this button oh, this is more suitable for the meeting when boring look at the code, And power saving does not affect you to see the code. Eclipse has a F2 feature that allows you to view the Java file definition, which you might need to configure in the spring configuration file, but this is not necessary in IntelliJ, because support for spring is perfect, You only need to enter the class name in the attribute of class and then

Related Article

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.