[TUTORIAL] Intellij IDEA

Discussion in 'Resources' started by CaptainBern, Nov 29, 2013.

Thread Status:
Not open for further replies.
  1. Welcome
    Since I’ve noticed the lack of good tutorials about the usage of Intellij I deiced to start a small tutorial series which will teach you the following things:
    ·Switching over from Eclipse
    ·How to setup your project
    ·Building your module
    ·Integration with Git
    ·Using Maven
    To start with this series I suppose you already have setup Intellij on your computer. I will not spend any time explaining how to install it.
    Since many of you will be switching over from Eclipse to Intellij I will also explain how to do that, and what you should know.


    Part 1:
    Switching over from Eclipse to Intellij
    Intellij provides a build in feature which allows you to open up your Eclipse .project or .classpath files. When you want to open up an Eclipse project just follow these steps:
    [​IMG]
    1.0Open up Intellij and then click on the “import” button.

    [​IMG]
    Navigate to the .classpath or .project file

    Now there should show up a new window and it will guide you trough the process, It’s as simple as that.
    Some things you should know:
    In Eclipse what is called a workspace is in intellij called a project. What is called a project in Eclipse is called a module in Intellij.
    In Eclipse you have a jardescription, in Intellij you have a buildartiffact. (Intellij does not have an export > jar option).
    I will not go any deeper in this subject. If you need any help, feel free to ask below.
    Part 2:
    Setting up your project
    Setting up a new project in Intellij is quite easy. I won’t add any screenshots since I do not find it necessary.
    Some things you should know:
    Intellij has build-in ant, maven, groovy, git and android tools.
    The features you will be using most are probably maven and git.
    I will not go about ant nor groovy or android (since this has no point)

    Like in the previous part, if you need any help, ask below :)


    Part 3:
    Building your module
    There are many people that use Intellij but very few of them don’t know how to build with it. It’s quite easy though.
    The first step is creating a build artifact; this is how:
    [​IMG]
    Click File | Project Structure


    When you have done that you should see this window:
    [​IMG]
    Now click on “Artiffacts”, now you should see this: [​IMG]
    Click on it and then the wizard should take you trough the setup. When you have done everything right you should now be able to do: Build | Build Artiffacts.. > then you should see the name of your artifact with some options on the left side, here you should press “build”. Now you’re done.


    Part 4:
    Git integration
    The git integration in Intellij is slightly different from the Eclipse eGit plugin. I find it better in use.
    Now, let’s start. I will do the best I can to explain this properly but please note that I haven’t figured this out myself yet, I do know how to do it and how to get it work but there are probably better ways to do so. Also there is the VCS | Import into version control | Share project on Github, I will not use this method since I myself never got it to work.
    Let’s start.
    The version control system is easy but a little bit tricky. I will not go about installing Git (yes you need to install it) If you have no idea how to install it, feel free to ask below, a good soul will definitely explain it to you.
    Anyways, enabling version control (I will now use the term VCS when referring to version control) you should click the VCS button in the toolbar:
    [​IMG]
    When you did that you should click on “Import into Version Control”, then click: “Create Git Repository…”, then navigate to your module folder and select that as the git location.
    Now you’re basically set. There’s only one thing you need to do now; creating your git repository. I’m supposing you already know how to do that, in github it’s just “new repo” and you’re set. Then when you have done that you have to copy the url of your repo (eg: https://github.com/CaptainBern/AnimationLib.git) then go to the folder your project files are located in and shift – rightclick > “Open command prompt here”. (I would have no idea how to do this on a mac or Unix/linux based system)
    Now type in: git remote add origin <url here>
    git push origin master
    Then go back in Intellij and press File | Synchronize. Then do: VCS | Git | Fetch. (Don’t forget to commit first! (VCS | Git | Repository | Commit)) Now you just need to add the files you want to the git (right click on the file > Git > Add or press Ctrl+A+Alt)
    Then push to the repo, if there are no erros you are set. If there are any errors, ask below…

    Part 5:
    Using Maven
    For this tutorial you already need to have maven setup on your machine. Intellij has amazing maven support. Why would you use maven? If you’re using git + Jenkins it’s necessary to use maven to handle the dependencies.
    When you used to be an Eclipse user and worked a lot with Maven you are absolutely going to love Intellij’s Maven support.

    1: You can easily create a Maven project by just creating a project but instead of clicking Java Application you have to click Maven Project.
    (If you have a project and want to add Maven support for it you simply have to right click on it > Add Framework Support… > Maven)
    Intellij will create a basic pom.xml for you, it looks like this:
    Code:
    <project xmlns="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>me.captainbern</groupId>
        <artifactId>AnimationLib</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    </project>
    Ofcourse for it to be useful you need to add bukkit as a dependency.
    (I will not go about this)
    Now, you will wonder why is the Intellij IDEA Maven support better than Eclipse? Well, see it yourself! Click View | Tool Windows | maven Projects. On the right side there should pop up a little windows, click on the arrows to unfold the tools. If you’re a frequent maven user you will definitely be loving this.




    Well that’s it for now. I will now no longer continue this tutorials, I’m now asking you, the community, to continue it. Found out a neat trick or a cool feature in Intellij that you want to share with us? Write a nice post in the comments and I will add a link to it in the main post! Free likes included!

    If you have any improvements or things to say, feel free to do so. Sorry for the font/markup looking a bit weird since I wrote it in word and copy pasted it in here (without doing shift-c-ctrl).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. Offline

    Ultimate_n00b

    I'll probably read this later when I try Intellij. I've tried it before and I found it confusing compared to eclipse (probably because I've used eclipse a long time).

    Intellij has a nice dark theme, however I was able to modify eclipse's css to match it :D
     
  3. Offline

    iiHeroo


    IntelliJ is so much better. I use it now, but I didn't import the project actually, I just opened up Eclipse and copied it :p And Maven is made it so much better.
     
  4. Offline

    Ultimate_n00b

    You can use Maven in eclipse.
     
  5. Offline

    iiHeroo


    I know that.
     
  6. Offline

    xTrollxDudex

    CaptainBern
    I was thinking of doing something like this, but lost the idea, good tutorial though :)
     
  7. Offline

    hawkfalcon

  8. Yey thanks for the nice feedback :). I will probably rewrite it a bit and correct some mistakes.
     
  9. Offline

    MarinD99

    I have a problem with Intellij. I started using it today and everything was going fine, until I tried to configure ma SDK. It says that my Java file is not a valid home for my SDK. Could anyone help me? I would really appreciate it!
     
  10. MarinD99 You need to navigate to your jdk.
     
  11. Offline

    MarinD99

    CaptainBern I did it and it works now, thanks! Switched to Intellij!
     
    spoljo666 likes this.
  12. Offline

    michael566

    Nice Tutorial! Very detailed!
     
  13. Offline

    viper_monster

    CaptainBern, after I have setuped the building module and after I have built the jar its 16Mb big :O and it should be around 100kb. Here is my setup: [​IMG]
     
  14. spoljo666 see the two tables? In the left one there should only be compile output, remove all the other files.
     
    madmac and viper_monster like this.
  15. Offline

    viper_monster

  16. Offline

    NoChanceSD

    Does Intellij have a debug function like eclipse that allows to go step by step?
    Because debug saves me a lot of time when fixing bugs, using that with jrebel helps a lot. If Intellij has something similar i will probably give it a try.
     
  17. NoChanceSD Intellij does include a debug system but I wouldn't know if it is similar to eclipse as I never debugged with eclipse.
     
  18. Offline

    The_Coder

    I just downloaded intellij, and tried it out. A friend of mine says that that you can step over in intellij just like eclipse.
     
  19. Offline

    Ad237

    CaptainBern I finally decided it's time to switch from eclipse but I'm having a bit of trouble setting this up. When I try to build any jar file I get an error saying I have not specified an SDK. What is that? I didn't have to specify one with eclipse.
    Thanks.
     
  20. Ad237 The SDK (also known as JDK) is a set of libraries and tools needed to build java apps. Take a look here for more info on how to set this up in Intellij.
     
  21. Offline

    Ad237

    CaptainBern Thanks it worked! I have one more problem. I can not create a yaml file. Because of this I cannot create a plugin.yml. It says yml cannot be found.
     
  22. Ad237 Hmm, thats weird. Normally you should be able to do: File > new file > plugin.yml and it should be there.
     
  23. Offline

    DSang

    How to auto replace Maven variables(ie:${project.version}) into our plugin.yml and class files ?
    This is a screenshot of my workspace in the case of something will be not be corectly configurate.
    [​IMG]
     
  24. After I switched from eclipse I've got 2 questions:
    1. intelliJ shows me some usefull tooltips sometimes (e.g:
    Code:
    'getChatChannel().getChatPermission() == null ? true : hasPermission(getChatChannel().getChatPermissi...' can be simplified to 'getChatChannel().getChatPermission() == null || hasPermission(getChatChannel().getChatPermission())'
    ), but is there a method to apply this tip like in eclipse, or do I have to do it manually?
    2. I get an "Ambiguous method call. Both" error when I use
    Code:
    for (Player p : Bukkit.getOnlinePlayers()) {
    . I know what it wants, but in eclipse there wasn't an error, but only a warning. How can I fix this?
     
  25. Offline

    DarkBladee12

    CaptainBern Looks interesting and well written, I think I'll give Intellij a try ;)
     
  26. Offline

    DSH105

    1. A little icon should appear on the left hand side of the editor for corrections/suggestions. It will be either yellow or red depending on what it is suggesting.
    2. It will still compile and means the same thing as in Eclipse :).
     
  27. Offline

    ZodiacTheories

    Where is Onlineids ?? :eek:

    Ill say it for him <3

    Ewww, IntelliJ
     
    Onlineids likes this.
  28. Offline

    DSH105

    You have not lived :(
     
    Garris0n likes this.
  29. Offline

    ZodiacTheories

  30. Offline

    Garris0n

    See, with the Windows vs Mac thing, I can at least sort-of understand why somebody would torture themselves with Windows.

    But Eclipse over IntelliJ? That's just objectively a bad. It's not even personal preference. I do not understand you ಠ_ಠ
     
Thread Status:
Not open for further replies.

Share This Page