LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-17-2008, 04:15 PM   #1
redmoon zero
LQ Newbie
 
Registered: Sep 2004
Posts: 18

Rep: Reputation: 0
Java: executable jar files on xp mac and linux


java is a platform independant language

but when i compile my program on xp or fedora8 it worked only on xp and fedora8 but not mac
also i tried it on an older xp machine and it didn't work

when i compiled it on mac it worked on mac and xp but didn't try it on older xp yet

this seems to be a issue with some version number
only thing i saw was maybe multiple jre's installed or compiled with different versions ???

i dunno
it is kinda lame ... i thought java worked anywhere but i had to do a little work to make this so

i had to get my hands on a mac and compile code there then when i made jar file it seems to work everywhere

also when i try to double click my executable jar file in linux
fedora 8
it seems to treat it just like a archive file like a zip
why didn't it run the program
and how would i make it an application for linux
and why does it only seems to be platform independant when complied w/ mac
 
Old 03-17-2008, 04:25 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
I would start by running:

Code:
java -version
on all your machines. Java is mostly backwards compatible, but not forwards. If you compile some source with a Java 6 compiler, it won't run on a Java 5 runtime.
 
Old 03-17-2008, 04:35 PM   #3
redmoon zero
LQ Newbie
 
Registered: Sep 2004
Posts: 18

Original Poster
Rep: Reputation: 0
when i can get to them i will
just a little lame - this issue is mucking up one of the beauties of the language

java -version = 1.6.0_03 on this xp laptop
i downloaded it not too long ago and on fedora8 i used whatever comes with eclipse on the install dvd
as far as my families mac's ... hell i dunno whatever comes with them
my dads is new and mom and sisters are older

i assume this laptop is newer than most if not all of the other machines so i don't get it ... i guess that word MOSTLY backwards compatible is the key

why would 6 not run on 5 ... isn't that what backwards compatible means
 
Old 03-17-2008, 04:46 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,458

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
You can compile with a newer version code that can run on an older JVM. Just use the "-target" option. eg: javac -target 1.4 ...
 
Old 03-17-2008, 04:55 PM   #5
redmoon zero
LQ Newbie
 
Registered: Sep 2004
Posts: 18

Original Poster
Rep: Reputation: 0
ok but would that be equal to compiling with that version
or does that make it backwards compatable
like ... do i lose the ability to now run with the newer version i have

say i run this from my xp laptop that has 1.6 i guess
javac -target 1.4 Program.java
then will it run only on 1.4 or will it work on 1.6 and 1.4
know what i am asking . . .
 
Old 03-17-2008, 05:17 PM   #6
redmoon zero
LQ Newbie
 
Registered: Sep 2004
Posts: 18

Original Poster
Rep: Reputation: 0
wait i think i get it
it needs to be compiled w/ oldest version to work on them all

if compiled w/ 1.6 it will only work for 1.6
if compiled with 1.5 it will work for 1.5 and 1.6 machines
if compiled on 1.6 with 1.4 -target switch it will work w/ 1.4 and greater

am i understanding it ?
 
Old 03-17-2008, 06:08 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,458

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
That's it.
Use a 1.6 javac with -target 1.4 and your class will be runnable by 1.4, 1.5, 1.6, 1.7 and so on.
 
Old 03-17-2008, 06:18 PM   #8
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You've got a couple of different problems here:

1. You seem to think double-clicking on a .jar should run it as a program

Granted, that might be convenient in some cases. It might be downright annoying in other cases. What if you need multiple .jars? What if you have multiple different "main()" entries? What if you just want to look at the contents of a resource .jar? What if it's malicious? Etc etc ad nauseum...

Bottom line: nobody says it has to work this way; and, more often than not, it simply *doesn't*.

2. You are correct: your Java Runtime must be greater than or equal to the Java version that the .class files in the .jar were compiled under.

There are many ways to achieve this.

For example, you can make sure the latest/greatest runtime is loaded. You can install *multiple* runtimes (and switch between them with a simple environment setting, like $JAVA_HOME, or changing your -classpath). Or you can explicitly tell a new compiler to write .class files compatible with an older version (e.g. -target).

'Hope that helps .. PSM

Last edited by paulsm4; 03-17-2008 at 06:19 PM.
 
Old 03-17-2008, 07:01 PM   #9
arkinrome
LQ Newbie
 
Registered: Mar 2008
Location: México
Distribution: Slackware
Posts: 15

Rep: Reputation: 1
I had the same problem and yes the target was the problem, I wish I had seen this before.

Regards.
 
Old 03-18-2008, 01:35 PM   #10
redmoon zero
LQ Newbie
 
Registered: Sep 2004
Posts: 18

Original Poster
Rep: Reputation: 0
paul

what do you recommend then
java doesn't compile into any executable format
executable jar seems the best
all you have to do it double click and it runs the program
just run jar xvf filename.jar to extract it

my dads mac has this cool xcode developer tools that can make .app files from java files

seen things like this for windows but they seem to cost money

i made a sudoku game for my grandma and this seems to be the best way to give it to her ... all she has to do it get one file and double click it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java executable Files John_Emad Suse/Novell 11 06-22-2005 10:01 AM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 05:26 AM
Installing Java running jar files jariep Red Hat 1 04-12-2004 11:11 AM
executable jar in java (cannot double click) spyghost Programming 3 09-29-2003 09:13 AM
Converting perl files to executable mac files mrozkan Programming 0 04-16-2002 09:56 AM


All times are GMT -5. The time now is 05:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration