Setting global environment variables in IntelliJ IDEA and other test config goodies

2012-05-09  |   |  tool   ide  

When you run a test from IntelliJ idea, you can customize some of the settings by selecting the list of tests and click Edit Configurations. From there you can change things like:

  • under which module classpath the test is run
  • the working directory the test should run from
  • virtual machine parameters
  • specific environment variables to use

In Hibernate OGM, we use the same test site for all NoSQL solutions. Changing the module classpath is useful in this situation. We also let you refine via an environment variable which hostname runs say MongoDB.

Unfortunately in Mac OS X, graphic applications do not inherit your .bash_profile config. I know, stupid, but what can you do against the Empire? Workaround!

You can set environment variables from each test but it gets tedious quickly. Alternatively, you can set an environment variable globally in IntelliJ - what they call parent environment variables. Go to Preferences and search for Path Variables. Set your global environment variables here and you are good to go. Note that you can ask a test not to inherit these global variables if you want to - in the test configuration.


Update:
It turns out I was wrong. Paths Variables is not where global environment variables can be set. If you know where, please let me know.

Update 2:
To set an environment variable visible by applications in Mac OS X, use

launchctl setenv MYPATH myvar

then restart your IDE (you might need to log out and back in as well).

Thanks @aagahi for the info. This is not great as it's remote from my IDE but at least that works. BTW, launchctl is supposed to set the data in /etc/lanuchd.conf or $HOME/.launchd.conf. Not on my system. If anyone knows where the data is put, I'm interested.


Notes to JetBrains:

  • your environment variable UI is plain counter productive: either give us a text free area or make tabs and co working
  • an option to inherit the .bash_profile configuration would be awesome :)


Mac OS X and IntelliJ crashes

2010-12-07  |   |  apple   ide   tool  

I've struggled in the past several weeks with repeated crashes from IntelliJ IDEA on Mac OS X. I suspect it started right after the upgrade to 1.6.5 and the latest Java VM update.

It seems it was cause by a couple of things.

Job scheduler crash
If your crash report shows something like
Thread 55 Crashed: Java: JobScheduler pool 1/2
This is a bug in the garbage collector. You need to pass an additional VM option to fix it
-XX:-ReduceInitialCardMarks
Open /Applications/IntelliJ IDEA x.y.z.app/Contents/Info.plist and update the VMOption key
<key>VMOptions</key>
<string>-XX:-ReduceInitialCardMarks -Xms128m -Xmx512m -XX:MaxPermSize=250m -ea -Xbootclasspath/a:../lib/boot.jar</string>
Font corrupted
Not sure if that was related to the previous issue but I initially had crashes with a different report involving directly the Garbage Collector (GC). My IntelliJ IDEA was using the Inconsolata font which apparently was somehow corrupted.

Removing fonts from ~/Library/Fonts solved the issue. What you can do is move them to a different directory and slowly re-inject them to find the culprit.

I am quite happy all this is behind me. I chose:

  • A Java VM
  • On Mac OS X
  • with IntelliJ IDEA

to precisely avoid this kind of bad experience and time waste :) Back to normal.


IntelliJ's Live Template

2010-08-25  |   |  ide   java   tool  

If you remember, I like to write my getters this way (long story here)

public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
private String name;

I have been doing it manually for a while but it turns out IntelliJ has a super nice feature for that: Live Templating which allows you to use parameterized and contextual templates to generate code.

Go to your Settings->Live Templating and create a new one.

Add this template:

public $TYPE$ get$UpperName$() { return $lowername$; }
public void set$UpperName$($TYPE$ $lowername$) { this.$lowername$ = $lowername$; }
private $TYPE$ $lowername$;

Then edit the variables:

  • TYPE: the expression should be classNameComplete() to refer to the class name context
  • lowername: the expression should be decapitalize(UpperName). Also tick skip if defined to not have to validate the computed value (this saves you one key stroke).

I've named my Live Template "get". When I type "get" and TAB, I am asked to type the property type (which is suggested). The second variable asked is the capitalized property name. Then the Live Template infers the rest (decapitalize my property name to fill up lowername).

Pretty nice feature!


Name: Emmanuel Bernard
Bio tags: French, Open Source actor, Hibernate, (No)SQL, JCP, JBoss, Snowboard, Economy
Employer: JBoss by Red Hat
Resume: LinkedIn
Team blog: in.relation.to
Personal blog: No relation to
Microblog: Twitter, Google+
Geoloc: Paris, France

Tags