Transfer from eclipse to IntelliJ idea

Source: Internet
Author: User

I use IntelliJ idea in fact not too long, after using this period of time, I think it is very useful. A lot of people who just turned from eclipse may not be able to get used to it, and I share some of the experience and common features in the process, and of course, before reading this, I recommend that you read IntelliJ idea's 20 auto-complete features, which describes the auto-complete features very well, Just the shortcut key Description section can also be more complete, can take care of the default binding keys inconsistent child shoes. This article in the description of the shortcut key is based on Mac OSX 10.5+ default Keymap, of course, will also provide relevant text description, if and my binding inconsistent can be directly to keymap search.

Basic settingsShow line Numbers

This was a very simple question in eclipse, and some of the people who have moved to IntelliJ have asked this question. Set up in the same way later discovery only works on the current file, and opening another file still has no line number. It's like you're just executing commands in vim set number , rather than setting the same effect in. vimrc. This needs to be set in the IDE settings, check it: Other settings can be selected by reference to this setting, such as displaying spaces and so on.

File and navigation associations

We often need to open a file when writing code, want to automatically open the file tree on the left link to the location, 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 set in Eclipse is also very simple, but intellij inside a little bit different, if you want to temporarily, open the file when you click on the small Earth (very much like a small globe at the first glance) icon if you want to be the same as eclipse, let it all automatically, Then in the floating layer can see two options AutoScroll to Source and AutoScroll from source , IntelliJ is very user-friendly sub-two settings in the inside, you two are checked is the basic and Eclipse features maintained exactly the same, just tick a natural also can.

There is also a way to use the Navigation Barprovided by IntelliJ, IntelliJ a lot of functions can be keyboard, this is like the keyboard operation of the necessary functions, 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, you can use the upper and lower keys to choose other directories, is not cool?

Note: here is suggested to put View > Navigation Bar the option point off, so that the use of shortcut keys will appear in your mouse position, the feeling will be more input, of course, you will basically lose the right to use the mouse, which requires you to use according to personal quirks.

Shortcut keys to use

If you are an Apple Computer user, it is recommended that you change to Mac OSX 10.5+ 's keyed bindings, because Mac OSX 10.5 is a Windows-compatible version of the keys are too lame, it is really uncomfortable, like your default ?+w is to turn off the label, In this key binding, it is a shortcut to select text based on a symbol.

Here are the main introduction of several may be commonly used, or you may not know IntelliJ in some of the shortcut keys, especially commonly used by you directly refer to the official website of the Keymap introduction getting started on it can be. Learn in the keymap of their own query needed shortcut key is the main, do not open the useless Baidu every time, the specific can refer to the link at the end of this article.

Outline Pull Out

Before in eclipse a lot of a shortcut key is ctrl+o , this can bring up all the member variables and methods of the code file, and can support the search is very convenient, IntelliJ this basic function is naturally, novice's words also often ask, this intellj in the shortcut key is ?+F12 (File Structure). If you are not a Mac OSX 10.5+ keying, the content in the parentheses is what you can search for in Keymap.

Basic operations
  • copy an entire line or block: in Eclipse, ctrl+alt+Up IntelliJ default is ?+D (Duplicate Line or Block) that there is a gap between this and eclipse, especially when there are multiple lines or when the content is selected, do not believe you can try. So you can put the definition of Keymap in Duplicate Lines a shortcut key, I define that Option+D this key in my default binding is not any shortcut keys, you can bind a try.

  • Select text according to the 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> you cursor in the milestones in a certain position, you want to replace the SpringSource Milestones Proxy other words, false ideas replaced by Test XX , In fact, you only need Option+Up (Select Word at Caret) two to select the words you want, when you want in the development process, you will find that the keys used too much, more than the other without the keys of the editor or IDE, is not used to.

  • Delete whole line: can be directly ?+delete (Delete Line) or take advantage of IntelliJ intelligent function, cut the shortcut key, when the bank selects the text when the cut `?+x will follow the selected text to achieve the cut, but you do not have any selected text in the bank automatically cut the entire line, Then nature is like a shortcut key to delete the bank, but this is actually quite lame, recommended to use ?+delete .

  • to jump directly to the interface implementation method: ?+option+鼠标单击 or ?+option+B .

  • Statement Auto-Complete statements Completion: This is in the IntelliJ idea of the 20 code automatic completion of the features have been explained, here is still focused on, because it is very useful, but also strongly recommended, and the article said 智能自动完成 ctrl+shift+Space , When you have too many tips, this key will definitely surprise you.

  • jump between the same words: the shortcut key in Eclipse is ctrl+k , this is very useful, in the IntelliJ also does not lack this function, but in the Mac OSX 10.5+ 's keyed binding default is empty. It is said that Windows is bound in the default binding, you can query under, I myself bound one ?+ctrl+k (Find Word at Caret) , no need to bind one myself, and then can be combined with other keys to ?+G (Find Next) achieve ?+Shift+G (Find Previous) the next function. It's very practical.

Version control settings

Our development is definitely version-controlled, when the previous eclipse when the local files and repository inconsistencies, then the file and the folder in which there will be a representation, it is easy to see the local files modified which some, but IntelliJ in the default is not the case. Just give changes to the file at the time of the change to provide color changes, not including its various parent folder Oh, if you want to like eclipse, you need to check the settings as well.
In fact, look at the English explanation can understand, this default after the opening if you want to adjust the display color of the folder when you go directly to Settings > Editor > Colors & Fonts > File Status Adjust, you can adjust to the way you like.

Java resource file non-English case display

IntelliJ in the resource file this personal feel is also a victory over eclipse, in the resource bundle mode to modify a property is quite convenient, you can modify the properties of all languages in an interface, all of this is done automatically, as shown in:

And it's nice to have a sort and grouping feature, especially this sort.

The default setting also has a problem, that is, Chinese default will be displayed as Unicode code, in fact, check a setting ( Settings > File Encodings ) can be, such as:

This way, all Unicode displays will automatically be converted to the language they should display.

How a Web project that conforms to the MAVEN contract structure works better

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 the time of each Web project modification must deploy, modify the things will be executed, It's very painful. Later on their own use of the Tomcat plug-in, this can ensure that you modify the JSP and static files do not need to deploy directly can be executed, because the Tomcat directory pointing in fact directly to your project files, so it is really worry a lot.

In IntelliJ If you are the traditional Java EE structure (the root directory has src,webmoudle such a structure), then add a tomcat directly in the run configurations, click the + sign to add ( Of course you need to be aware that although there is no search box, you can automatically filter the results by typing characters so that when you run the Java file, you need to make project active ?+F9 (Make Project) . But if you are in a project structure that conforms to the MAVEN agreement, it is not ideal to continue with this configuration. It is also necessary to make project to modify the JSP file every time, because IntelliJ will automatically give you a deployment after each make project, which seems to be back to the troublesome environment a few years ago.

This problem is easy to solve, just do not use this way to run your Web project, since the MAVEN structure of the project is naturally using MAVEN or gradle This build tool, then you need to use MAVEN jetty plug-in to run the project, such as configuration:

Of course, you can also automatically add one if you click to run it directly:


See actually also did not have to use jetty, with TOMCAT6 or TOMCAT7 plug-in operation also can.

How eclipse Web Fabric projects are imported and run

Given that some users have not yet transformed Maven to build the project, of course, I would like to say a heartfelt word, Build this piece or make a quick turn. Because not to turn the words also come out of this chapter alone, and some operations are still quite troublesome, the following will also talk about, or one by one way to come, when the import has two choices then I divided into two parts description, click File > Import Project… , then select your project directory, click OK, such as:

Use the new project to import

The first type shown in this way, the import is basically the next to complete, but you can also pay attention to the first time to do something, for example, to help you analyze what the jar, if you use spring also to analyze all your configuration files. After the final completion of the project began to build the index, and so everything is ready we can complete the basic configuration, because the Web project is basically able to run on the Tomcat and other servers on the basic count of success. Several main points:

    • Handle dependencies because we're not using MAVEN, so you have to get your hands on your own.

    • Set the compilation path of the Java file, if necessary

    • Add your tomcat, run successfully

Dependent relationships

Open File > Project Structure , we mainly use several red parts in this section:
Let's look at these main components first:

    • SDKs: The main storage of our JDK, such as (i download the JDK with source, so that you can directly see the Java source code related to the JDK):

    • Global Libraries: The main common jar files, such as several jars of the servlet, may be required for each project, but the eclipse variables are not working so well, so you need to use this place to configure, as the reference is used:

    • Facets: do not introduce here, if necessary to add later

    • Libraries: Here is basically the library of the project, not the overall, the imported project will generally put you in eclipse. All dependencies in Classpath are directed as a Lib library and then applied to the module of your project

    • Modules: This basically includes the project's module, which is usually a single module in the project structure of Eclipse.

We need to do the configuration mainly in the modules, the other several of their own according to the understanding configuration can be.

    1. Let's look at the Sourcesin Modules first, such as:
      The project all the source code can be added, the figure shown in my project is actually less resource folder, so I select resource and then click Sources, so that will be in the left source folders to add a resource folder.

    2. Then is the paths section, this is the output path of the class, the default is in the root directory of the Out folder, if the project in the configuration file parsing and other write dead path, you must strictly follow the Java EE specification, then you need to modify this section as follows ( If I don't have a hypothetical scenario, ignore this step):

    3. Then the dependencies is better configured, adding the required dependencies.

After these steps we can click Run > Edit Configurations , click on the + sign in the upper left corner, then select **tomcat > Local Server * *, these steps are similar to eclipse, select the appropriate path and so on, only need to pay attention to, is to add a deployment, such as:

if the + sign in the deployment in the graph of Windows is probably on the right , clicking on it will pop up the dialog box and select the default Webmoudle folder for Eclipse (MyEclipse is the Webroot folder). This must not choose the wrong, do not choose 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 refer to the previous section.

HQL Query Support

Before Eclipse has a HQL plug-in can directly enter the HQL syntax, query test results are correct, in IntelliJ you can, but do not need any plug-in default support, if you import the project without automatically add hibernate support, That need to add hibernate support, mouse selected items, right click like:

Click to select Hibernate, if not hibernate should be the project has automatically added hibernate support. Then you can do it as follows:

Select the above hql icon, in the console input you want to enter the HQL can be, as the automatic completion of OH.

Precautions
  1. IntelliJ for the file is the default at any time to save, basically do not need you ?+s (this key is saved all by default), so you need to be careful not to accidentally change a file, and then directly close the label, in fact, your unintentional operation has resulted in the modification of the file, May cause you to find a very strange error while the project is running, I have not found that I can turn off AutoSave settings, and if you are not obsessive about it, vim plugin may help you.

  2. The files in the IntelliJ are synchronized in real-time and local files, so the refresh feature of Eclipse is not asked because it doesn't need that feature at all. Some editors will remind you whether or not to update the local files, here is also the default does not give any reminders, as long as you modify, here will automatically synchronize the update files.

  3. Under the main menu File , there is a strange power save mode, which is also illustrated here, as the name implies the power-saving model. When you tick this mode, IntelliJ will not give you to complete any auto-completion functions, such as the original you entered a character will automatically prompt, tick out later, if there is no, if this problem can be considered if you have the hand of the button oh, this is more suitable for the meeting when bored to see the code, It also saves power and does not affect the code you see.

  4. There is a feature in eclipse that F2 allows you to see the Java file definition, you may need to configure this value in spring's configuration file, but this is not required in IntelliJ, because support for spring is perfect, You only need to type the name of class in the class's attribute and then ctrl+空格 (Basic 这个在code的completion下面) complete the path automatically, and in the smart condition you may not need a crappy implementation.

  5. When the project started to import or clear the cache re-open, the following status bar section will show indexing, this time you will be able to wait, the basic things you want to do nothing to do, do not worry about this time point to point, but it index speed is very fast, do not worry.

  6. Eclipse has a Save actions function, mainly for Java can be automatically formatted and optimized import and other functions, this on IntelliJ is not the default, in order to use this feature in IntelliJ can use the following two ideas:

      • With macro recording , the macro starts after you format the code, then optimizes the next import and so on, and then ends up defining a macro, ?+s but the problem is that no matter what file will execute the macro, not just the Java file, I am using this macro mainly to complete the tab to a space.

      • With Eclipse Code Formatter plug-ins, this plugin is basically similar to eclipse's default functionality, but there are a few differences, and the user thinks about whether to use it.

  7. The IntelliJ code area under Mac supports gesture amplification, which is handy when it comes to demonstrating to others. But run, debug and other views when the default can be thought of is the manual drag size, it is inconvenient. You can try ?+shift+up/down (Stretch to Top / Bottom) , of course, other project views and so on can also use this shortcut to configure the next left and RIGHT ARROW keys to configure the use, convenient, highly recommended use.

A few tricks
    1. IntelliJ rarely see the search box, where there is really no search box where you try to enter pinyin directly, such as your view in Project, open the directory tree after you directly type the letter, if there are qualifying records then there will be highlighted.


Transfer from eclipse to IntelliJ idea

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.