Showing posts with label IntelliJ IDEA. Show all posts
Showing posts with label IntelliJ IDEA. Show all posts

5/18/2017

Building IntelliJ Idea Community edition on Ubuntu 16.10

Building IntelliJ Idea on Ubuntu is just a bit more complex than simply executing ant.

Acquiring dependencies

The commented lines below are required if you wish to use jdk1.6; in practice, things seem to build without (as of May, 2017 at least)

#sudo add-apt-repository ppa:webupd8team/java
#sudo apt-get update
#sudo apt-get install oracle-java6-installer
#sudo update-alternatives --config java
sudo apt-get install zlib1g-dev ant git
mkdir $HOME/tools
cd $HOME/tools
git clone git://git.jetbrains.org/idea/community.git idea
cd idea
./getPlugins.sh 
build/conf/install_nsis3.sh $HOME/tools/idea

If the build finishes with

...
scons: done building targets.
...the build of dependencies finished successfully.

Starting the build

If you've installed JDK1.6 (the commented lines above), here we need to refer to it (first line below). Again, IntelliJ Idea Community Edition builds without this, so left it commented out.

#export JDK_16_x64=/usr/lib/jvm/java-6-oracle
cd $HOME/tools/idea
ant

6/01/2015

IntelliJ IDEA: pass JAVA_HOME, M2_HOME, MAVEN_OPTS to the IDE using Yosemite

Place the following content (enhance it to your taste obviously) to /Library/LaunchDaemons/setenv.MAVEN_OPTS.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
  <key>Label</key>
  <string>setenv.BAR</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/launchctl</string>
    <string>setenv</string>
    <string>MAVEN_OPTS</string>
    <string>-XX:PermSize=500m -XX:MaxPermSize=800m -Xmx2g -Djavax.net.ssl.keyStore=/Users/doma/.keystore -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/security/cacerts -Djavax.net.ssl.trustStorePassword=changeit</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>ServiceIPC</key>
  <false/>
</dict>
</plist>

You'll have to either restart your computer or run the following line to apply the changes:

launchctl load -w /Library/LaunchDaemons/setenv.MAVEN_OPTS.plist

The next candidate is M2_HOME, the file to create is /Library/LaunchDaemons/setenv.M2_HOME.plist :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
  <key>Label</key>
  <string>setenv.BAR</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/launchctl</string>
    <string>setenv</string>
    <string>M2_HOME</string>
    <string>/opt/local/share/java/apache-maven-3.1.1</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>ServiceIPC</key>
  <false/>
</dict>
</plist>

Again, restart or run the following to apply:

launchctl load -w /Library/LaunchDaemons/setenv.M2_HOME.plist

...and here's the proof that you don't have to set the value of the M2_HOME after each Maven project import:

Reference: http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/


3/09/2015

IntelliJ Idea live templates: code for singletons

Say you have this class:

public class TerminalTitlebar {
    public void set(String title) {
        System.out.println("\033]0;" + title + "\007");
    }
}

...and you want to introduce code to change this into a singleton easily.

File -> Settings -> Live Templates -> Click + to create a new entry.

Enter i for abbreviation, "singleton instance" or something similar for description, and the code in the "Template text" field:

private static $CLASS_NAME$ instance;
public static $CLASS_NAME$ getInstance() {
    return instance == null ? instance = new $CLASS_NAME$() : instance;
}

Now click "Edit Variables", and change the Expression for CLASS_NAME to "className()", press OK

To tell IntelliJ to use the generated snippet in Java code, click "Change" in the "Applicable in" line, and select Java.

Now type the letter i (this was the abbreviation we used earlier) and press TAB and the magic happens:

public class TerminalTitlebar {
    private static TerminalTitlebar instance;

    public static TerminalTitlebar getInstance() {
        return instance == null ? instance = new TerminalTitlebar() : instance;
    }

    public void set(String title) {
        System.out.println("\033]0;" + title + "\007");
    }
}

Voila, you can use it in any class. Enjoy!


1/19/2015

Automatic logger generation using IntelliJ Idea's Live Templates (use it with log4j, slf4j, commons-logging, etc by changing the template line accordingly)

In IntelliJ Idea, go to File -> Settings -> Live Templates, and click the + sign. Fill in the details:

  • Abbreviation: log
  • Description: log
  • Check "Reformat according to style" will indent the generated line appropriately.
  • Checking "Shorten FQ names" will remove "org.apache.log4j." and replace it with an import.

"Template text" is

private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger($CLASS_NAME$.class);

The same for slf4j is

private final static Logger log = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);

Now click "Edit Variables", and in the CLASS_NAME row, enter className() in the Expression column.

Almost done - we still need to tell IDEA that we need this for Java stuff. Where it says "No applicable contexts", click "Define" - click JAVA, and OK.

Open any of your classes, and into a newline under "public class Blah", type "log" and press tab - and the logger line will be created appropriately:

private static final Logger LOGGER = Logger.getLogger(HSQLSequenceGenerator.class);

10/21/2009

Mac OS X: Using IntelliJ IDEA on 64bit JDK6

UPDATE 2:
The retail version of IntelliJ Idea 9 uses the JDK6 32bit by default on Snow Leopard (in contrast with the betas which were using JDK6 64bit).
The article has been updated to reflect this.

IntelliJ Idea 9.0 - Mac OSX 10.6 Snow Leopard

The default installation of IntelliJ IDEA 9.0 uses JDK6 32bit on Mac OSX 10.6 "Snow Leopard". With a little configuration we can force it  to use the 64 bit JDK6, which is also part of the operating system.

After you installed IntelliJ IDEA, Cmd+click on the IDEA launcher-icon to open it in Finder. Ctrl-click on the IntelliJ IDEA icon and choose Show Package Contents. Select Contents and right-click Info.plist. Select Open with -> TextEdit. This brings up the file in the text editor.

Do a search (CMD+f) on the string JVMArchs. You'll find the following entry:

<key>JVMArchs</key>
<array>
  <string>i386</string>
  <string>x86_64</string>
  <string>ppc</string>
</array>

Put the x86_64 entry on top (e.g. swap the i386 and the x86_64 lines), save the file (CMD+s) and close TextEdit (CMD+q). If you restart Idea, you'll see it is using the 64bit JDK if you check it in the IntelliJ Idea->About.

You can also check if a given process is 64bit in Applications->Utilities->Activity Monitor. Check out the last column called Kind.

IntelliJ Idea 8.0, 9.0 - Mac OSX 10.5 Leopard

In contrast, Idea uses JDK5 on MacOS X 10.5 "Leopard", and that's 32bit only. Again just a little configuration and we can force it to use the 64bit JDK6.

After you installed IntelliJ IDEA, CMD+click on the IDEA launcher-icon which brings up the entry in Finder, now right-click (or ctrl-click) on the IntelliJ IDEA icon and choose Show Package Contents. Select Contents and right-click Info.plist. Select Open with -> TextEdit. This brings up the file in the text editor.

Do a search (CMD+f) on the string JVMVersion. You'll find the following entry:
<key>JVMVersion</key>
<string>1.5*</string>
Change the 1.5* to 1.6*, save the file (CMD+s) and close TextEdit (CMD+q). Since the JDK6 in Leopard is 64-bit only, we don't have to touch the JVMArchs section.

Start IDEA and check in About IntelliJ IDEA if it is indeed using the 64bit JDK6.

IntelliJ Idea 8, 9 betas: if IntelliJ does not start anymore, and honors us with a [JavaAppLauncher Error] unable to find a version of Java to launch in the log file, we have to replace the launcher with a 64bit executable. Open a terminal:

cp /System/Library/Frameworks/JavaVM.framework/Resources/MacOS/JavaApplicationStub64 /Applications/Maia-IU-90.94.app/Contents/MacOS/idea

Replace Maia-IU-90.94 with the proper name of your application - I was using a developer preview of IntelliJ IDEA 9, but this same method works for version 8 as well.

32bit or 64bit?

To me IntelliJ Idea seems more responsive on 64bit JDKs. I'm wondering if you consider it faster as well? If you are developing for JDK6 on Leopard you should use similar amount of memory now (the 64-bit JDK footprint is bigger but there's only one copy of the JDK in memory), and - as a question of personal taste - the display looks nicer since JDK6 uses the native font smoothing style of OSX (a mixture of regular antialiasing and subpixel rendering), whilst JDK5 uses plain anti-aliasing without subpixel rendering. There are some comments online about memory leaks using JDK6, but personally I didn't experience this.

Happy developing using this great tool!