aspose file tools*
The moose likes Linux / UNIX and the fly likes Jar file on linux ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Jar file on linux ?" Watch "Jar file on linux ?" New topic
Author

Jar file on linux ?

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
HI
I,am new to linux
I've made a swing application which is jared .
I have 2 questions :
1) Does linux always include JRE ?
2) Can a jar file run on linux ?
PLease guide me a bit .
Thanks in advance


Raghav.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16240
    
  21

1. Actually, I'm not sure that ANY Linux distro comes with Java, and I'm not even sure that even the antique Java version that Netscape "supports" comes with Netscape/Mozilla. However it's easy to install, so the only real problem is getting the 5MB or so worth of install package onto the machine.
2. Execution of JARs is just like in Windows command line:
java -jar jarfile.jar
if it's an executable JAR
java -classpath jarfile.jar mainclass.name
if it's not or if you want to override the default class to be executed as the main class.


Customer surveys are for companies who didn't pay proper attention to begin with.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
oh ! I always thought that linux provides a java runtime environment.
If the jar file on linux run in the same way as windows then it will open on a double click as we do it in windows.. hmmm .
What if mozzila is installed on a linux machine?Does that means JRE is installed on that pirticular machine ?
Please guide me a bit
Thanks in advance
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11506
    
  95

raghav: Does linux always include JRE ?
Tim Holloway: Actually, I'm not sure that ANY Linux distro comes with Java.

I don't think any Linux distrubution ships with the Sun JDK, but I think many of them ship with IBM's or other parties JDKs.
RedHat 9 provides:
jdkgcj:
jdkgcj provides an interface to gcj that is compatible with the Sun and IBM
Java Development Kits (JDKs).
jdkgcj provides the javac, java and javah tools as well as jni.h, allowing
you to compile java extensions using JNI.
I remember earlier versions of RedHat had kaffe:
Kaffe is a complete, PersonalJava 1.1-compliant Java environment. As an independent implementation, it was written from scratch and is free from all third-party royalties and license restrictions. It comes with its own standard class libraries, including Beans and Abstract Window Toolkit (AWT), native libraries, and a highly-configurable virtual machine with a just-in-time (JIT) compiler for enhanced performance.
(Wow - so old )
And another version of RedHat used to have the Blackdown implementation.
Having said that, I (and others) have noticed problems with RMI from other vendors. I had my RMI programs working happily with the Sun JDK on RedHat 7, did an upgrade to RedHat 9 and none of my RMI programs would work Took me a while to realise that in the upgrade, RedHat had installed a package that I had not asked for which had a different rmiregistry that was running instead of the Sun one. Once I removed that package everything was fine.
If the jar file on linux run in the same way as windows then it will open on a double click as we do it in windows.. hmmm .

I have no idea - I am a text based person, so I have always run my jar files from the command line.
....
OK, just started up a graphical screen and tested it. By default, KDE recognises it as an archive, and will open it for you in their archiving tool. It took me about 2 minutes to add an extra option so that I could optionally run it using java. It would probably take me about another 5 minutes to work out how to separate the extensions so that jar was not the same as zip, which would then mean that I could make the default action for jar be to run it under java (I could have done that already, but then it would have applied to zip files as well).
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16240
    
  21

Actually, when I double-click on a Jar in Windows, it runs WinZIP to show what's in the JAR. The action to be taken is determined by MIME settings.
The same is true in Linux, except the locations of the MIME settings is slightly more sane.
However, I don't think the standard distros are set up to run JARs by default and you should be polite and not simply stomp over any previous settings if you want users to like you.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11506
    
  95

I agree that you shouldnt arbitrarily change system wide settings.
I guess there are two issues then:
  • What should the default action be for a jar file?
  • At what level should this be done?

  • I can see value in having the default action for a jar file set to run it. The average end user probably won't know what to do with the extracted files. And the power user who does want to extract files (or view the archive) can manually choose their action. Of course this assumes that the jar files are configured so that they are executable.
    The other issue depends on what level you log in as when you configure the mime type. As an end user, KDE will save your modified action in a local configuration file - it won't affect anyone else. I just looked at the mime configuration panel as root, and it looks different to the configuration panel I saw as an end user, so I assume it is working on the master file.
    Regards, Andrew
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    Well ......
    It is difficult to understand what you guys are talking about cos i have not really explored Linux . I have a java application which is jared and should run on Linux . My question is whether it will run in the same way as on windows or would i have a to make some more effort for it to run on Linux. If yes then tell me what exactly do i have a to do .
    Thanks in advance
    Tim Holloway
    Saloon Keeper

    Joined: Jun 25, 2001
    Posts: 16240
        
      21

    The reason why we don't make sense is that there is no "same way as on Windows". Even on Windows, how a jar will be used (executed, unjarred, ignored or other) is dependent on how the system's MIME types are set up. I even have one system that for inexplicable reasons tries to open JARs with Excel.
    Microsoft doesn't love Java, so they don't set ".JAR" up as a standard type with a standard action. What you get will depend on whatever third-party software might have been used to set an open action on a ".JAR" file -- assuming that any software had done so. Just because double-clicking on YOUR Windows computer causes a JAR to be executed doesn't mean that you can expect the same to happen on every other Windows computer; like I said, none of mine do and never will unless I go in and change the registry settings.
    Just like Windows, Linux has no standard action for JARs. It's just that Linux doesn't mess with a registry. Linux just uses MIME definitions.
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    Thanks Tim
     
     
    subject: Jar file on linux ?