One of my pet peeves when working on Linux has always been that java applications do not work well with popular docks like Docky and Cairo dock. When you add a Java application as a launcher to the dock and use it to launch the application it will still create another icon in the dock, which in a way defeats the purpose of a dock. Reading the comments in following bugreport made it apparent to me, that this is not something that can be easily fixed by the dock’s authors, since the problem lies within the jdk. A workaround exists but it does not apply to all Java applications.
One of the applications the workaround does not work for, unfortunately is Intellij IDEA. The one application I use most on a day to day basis.
When you request the WM_CLASS for Intellij it will identify itself as java-lang-Thread
xprop | grep WM_CLASS | awk '{print $4}' "java-lang-Thread"
Which is not something that can be used to identify all windows belonging to Intellij. So I decided to see if I could work around this problem, and succeeded. Here’s what you do to make Intellij behave properly
UPDATE 23-01-2010 : whoah seems my original approach had some issues with classloading. (Who needs to create new classes anyway 😉 ) So here are the new and improved instructions.
1. Download agent.jar and copy it to Intellij’s bin folder.
I wont describe in detail what this jar does. But it’s something i created that changes the default value sun.awt.X11.XToolkit assigns to WM_CLASS. The sources are included in the jar
2. Open idea.sh And change the line that looks like
exec $IDEA_JDK/bin/java $JVM_ARGS $IDEA_MAIN_CLASS_NAME $*
to
exec $IDEA_JDK/bin/java -javaagent:agent.jar=Intellij_IDEA $JVM_ARGS $IDEA_MAIN_CLASS_NAME $*
3. Find the .desktop file that is used to start intellij by executing the following command from your home folder
find . -name '*.desktop' -exec grep -H idea.sh {} \;
4. Edit the file you found in step 3 and add the following line
StartupWMClass=Intellij_IDEA
Done!
Eens kijken of dit ook werkt…
works on my pc ™ 😉
Hi! It works great for Intellij, but could You please make such launchers for RubyMine and PyCharm?
I would be very thankfull 🙂 Thanks in advance 🙂
Are you able to provide the source code of launcher.jar? Who knows if you put some Java-based virus inside 🙂
Hi Thai Dang Vu, like i mention in my post, the sources are included in the jar file.
Hi Krzysztof, RubyMine and PyCharm are just specialized versions of Intellij i wouldn’t be surprised if my launcher works for those apps without modification. Did you try that yet ?
@Jelmer Kuperus
I think that Your launcher would work, but the problem is, that I’m using both RubyMine and PyCharm (sometimes even Intellij :P) and they’re all named “Intellij IDEA” (i’ve checked source code). It could cause some problems (i think).
Maybe You could create one launcher which would take the name of application (“rubymine”, “pycharm”, “phpstorm” etc.) from some config files.
@Jelmer Kuperus
I’ve just checked – it doesn’t work with RubyMine 3.0.1 (maybe with other versions too, i don’t know).
@Krzysztof Zalewski
I had to redo my fix due to some classloading issues, and in the process made it a bit more generic. The new one should work with any java app. Just change
-javaagent:agent.jar=Intellij_IDEA
to
-javaagent:agent.jar=SOMETHING_ELSE
for another application
@Jelmer Kuperus
Now it works with Intellij, RubyMine, PyCharm and PhpStorm (2.0-pre) (I’ve checked them all)
Thanks
🙂
Tried to do this in Ubuntu 10.10 with IntellJ IDEA 10.0.3 and it doesn’t work. There is no line that starts with exec… but I have changed the following loop:
while true ; do
$IDEA_JDK/bin/java $JVM_ARGS -Djb.restart.code=88 $IDEA_MAIN_CLASS_NAME $*
test $? -ne 88 && break
done
to
while true ; do
$IDEA_JDK/bin/java -javaagent:agent.jar=Intellij_IDEA $JVM_ARGS -Djb.restart.code=88 $IDEA_MAIN_CLASS_NAME $*
test $? -ne 88 && break
done
has someone managed to configure Idea 10 this way or am I doing something wrong?
I have checked with xprop | grep WM_CLASS | awk ‘{print $4}’ and it is still “java-lang-Thread”
Stanizlav Chekalin, I’ve got Ubuntu 11.04 (tried on Fedora 15 too) and IDEA 10.5 and this one works: http://goo.gl/ix8sD
Super, it works like a charm in Ubuntu 11.10! Thanks, awesome work!
Thank you so much, I wonder if you could submit your patch to JetBrains developers, who are now willing to take care about the problem that you’ve solved.
With PhpStorm 2.15 had to apply your fix here:
$WEBIDE_JDK/bin/java $JVM_ARGS -Djb.restart.code=88 -javaagent:agent.jar=JetBrains_PhpStorm $WEBIDE_MAIN_CLASS_NAME $*
now it works like a charm, thanks!
I did some work over your solution and created a Linux launcher! I just wrote a post about it.
http://ollivander.franzoni.eu/2011/12/jetbrains-ides-dock-aware-launcher-for.html
Just one more update:
IDEA 11 and above and PyCharm 2 and above don’t need the agent anymore, the WM_CLASS is set correctly by the IDE itself, and the .desktop entry can be created via Tools -> Create desktop entry menu.
For Intellij Idea 11 under Ubuntu 11.10 is enough to add at .desktop file the line:
StartupWMClass=jetbrains-idea
Hello
I tested on Ubuntu Unity Launcher, adding “-javaagent” arg into the idea.vmoptions file; and it works perfectly! Great
As long as I understood, it should work for any Java application, shouldn’t it?
Thanks
Hi,
Thanks for this tips, works like a charme, except that when you click the icon or hit super+the number corresponding to the icon, Idea does not take the focus. Any solution to this?
Got it to work under Linux Mint 13 (Maya) and IntelliJ IDEA 12 and Cairo Dock! There was no line beginning with ‘exec’ in idea.sh but I changed:
eval “$JDK/bin/java” $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME $*
to
eval “$JDK/bin/java” -javaagent:/home/john/Software/idea-IU-123.94/bin/agent.jar=Intellij_IDEA $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME $*
Note that I included the full path to agent.jar. It did NOT work UNTIL i did that.
Thanks Jelmer!
Thanks. One thing I had to do was put in the full path to agent.jar. Also, it’s possible to add that line to the .vmoptions file instead of editing the .sh startup script.
In case anybody is interested, I’ve documented a fix for eclipse here
http://glx-dock.org/bg_topic.php?t=7029
and here
http://askubuntu.com/questions/36434/how-can-i-remove-duplicate-icons-for-launched-java-programs-in-the-launcher/301864#301864