Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I just installed java according to this article, and java -version displays

java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

update-alternatives --config java' returns this:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                  Priority   Status
------------------------------------------------------------
  0            /usr/bin/gij-4.6                       1046      auto mode
  1            /usr/bin/gij-4.6                       1046      manual mode
* 2            /usr/local/java/jdk1.7.0_07/bin/java   1         manual mode

Press enter to keep the current choice[*], or type selection number: 

with update-alternatives --config javac (or javaws) returning similarly.

however Java isn't listed in the default applications menu when I click on a .jar file and go to "open with application".

  • I tried to install Java this way, and on the update-alternatives part of the command returned me:

    /etc/alternatives/[java,javac,javaws] is dangling, it will be updated with best choice

  • I just confirmed that I can use Java, as java -jar file.jar does work.

  • Just figured that I'd mention it, don't know why I didn't before, but when I right click on a .jar file, Java 7 run-time isn't even listed there, it seems that the file manager isn't recognizing it as a program, but it is there, and it does work...

CAUSE OF THE PROBLEM

After much experimenting, and research, I've found the cause of the problem - a missing .desktop file in /usr/share/applications. I've posted an answer that you can use to manually create an entry, but as stated it isn't recomended as I'm sure that there's a better way to do it.

share|improve this question

4 Answers 4

up vote 1 down vote accepted

I've patched together a way to do it, but it's not the recommended way of creating a .desktop entry (there's has to be a better way of doing it).

1) Open Gedit from the Terminal with root privileges usind gksu gedit

2) Open a .desktop file from /usr/share/applications and copy it into a new file.

3) Edit the name, comments, and image to your liking.

4) Change the command to java -jar %u DO NOT FORGET THE %u

5) Save

6) Right click .jar file in nautilus, select properties>open with>show all applications, and select the new entry, select either add or set as default.

share|improve this answer

I use this method too and the wikihow article missed two things. Not sure if this will solve your problem since I never run anything by double clicking .jars, but worth a try:

  1. Slave all the Java binaries (javac, javaw, etc) to the main java binary in your update-alternatives --install command. Without doing that, only the java binary is linked into /usr/bin/java, none of the others are. (I think wikihow assumes that if they're in $JAVA_HOME and $JAVA_HOME/bin is in the path the system will find them, but not sure about that). This also makes it much easier to uninstall, since you only have to update-alternatives --remove-all java, and all the slaved binaries are automatically included.

  2. Set the priority higher, not lower, than gij-4.6 and anything else listed, so the system will default to that instead. They set the priority to 1, which is lowest/last the way update-alternatives works. Yours needs to be at least 1047 or higher. I use 1100.

I've scripted the install, try this one and modify the directory locations for your setup (I use /opt/java/jdk/1.7.0_6 instead of /usr/local/java).

One note - the last line of the script installs the man pages as /usr/share/man/man.10. Before running the script, make sure to check /usr/share/man and ensure there's not already a man.10 in there. If there is, change the line in the script to man.11 or whatever the next highest number is.

share|improve this answer
    
This didn't work, it does make sense, and it may have fixed future problems, but not this current one. –  John Sep 2 '12 at 14:51
    
Darn. Don't have my linux box handy at the moment, but will revisit it when I do. Would be good to figure out how to get the clicking jars working. Maybe something to do with the desktop environment... –  Kurtosis Sep 2 '12 at 15:12
    
I have messed with my java (uninstalling it, only to install it with another method), and that may have messed it up, I'll remove all entries, and try again from scratch. –  John Sep 2 '12 at 15:25
    
After removing, and installing with my second link, it still doesn't work. Maybe something with the /etc/alternatives/java is dangling... –  John Sep 2 '12 at 16:02
    
Try a test. Instead of clicking your .jar file, start it in a terminal window with the command java -jar myfile.jar, and see if it works. If so, then the problem is with the way the Desktop Manager, Unity I assume, or Gnome if you're on an older Ubuntu, register java as the default runner for jar files. I'm not sure how that works, but pretty sure there's a configuration setting somewhere that lets you specify what program to associate with what file types. Just don't recall where off the top of my head. –  Kurtosis Sep 2 '12 at 22:22

I just figured this out: go to /usr/share/applications and look for the file 'defaults.list'. Open this file with gedit or your editor and go to line 81, where it says: application/x-jar=file-roller.desktop, and the next line for the java-archive. Change the file-roller.desktop in both lines to: openjdk-7-java.desktop and save the file. The next time you want to run a .jar file you can double-click it.

share|improve this answer

Just for the record, there's an easier way to fix this.

After installing OpenJDK Java 7, if you go to /usr/share/applications there is already a .desktop file for openjdk, all you need to do is change the bottom line

"NoDisplay=true" to "NoDisplay=false"

And it will show up in the default programs lists.

Sorry to jack your post like that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.