Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

I can't make a .jar file executable

 
Ranch Hand
Posts: 102
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh no!  I can't get java programs to run because it says they're not executable!  I tried making them executable two different ways:

- I opened the properties permissions tab and checked the box to make them executable, but it just checked on for less than a second and then automatically checked off again.

- I used chmod with the a+rx parameter and typed the sudo password, but it didn't change anything (though it didn't say anything, including any kind of error).

What gives?
 
Marshal
Posts: 70602
287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Terrance Samson wrote:. . . What gives?

Don't know. Please show us how you were trying to execute the files. Were they XXX.java files or XXX.jar? Please show us the exact instructions you used to alter the permissions.
 
Terrance Samson
Ranch Hand
Posts: 102
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not specifying.  I'm just trying to open a compiled runnable JAR file, and I get an error.  I got instructions from here to fix it:

https://itsfoss.com/run-jar-file-ubuntu-linux/

It's supposed to be for Ubuntu but says it will work on other distributions (I'm using Mint).  Anyway, I check the box to allow execution but it doesn't stay checked for more than a fraction of a second.  Then if I try using chmod on the file (with sudo in case I need the extra authority), it doesn't say any sort of error or imply that anything went wrong, but it still won't change the permission.  I really need to be able to run the JAR file just by double-clicking it.

EDIT: I think I figured out the problem (though I haven't tested it yet because I have to reboot in Linux, which I'll do soon).  The JAR files are on a USB drive formatted in either FAT32 or NTFS (I'm not sure which), so Linux can't set the file permissions.  It would be nice if that web page had mentioned that.  Anyway, if I copy them onto the ext4 drive I should theoretically be able to set the permissions, right?
 
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An "executable" JAR is not an executable program and therefore no OS file permissions settings will do any good.\

You cannot execute a JAR without a Java runtime program (JVM). An "executable" JAR is one where you can say:

and Java will find a Main-Class entry in the JAR's META-INF/manifest.mf file that tells which class within the JAR contains the public void Main(String []args) method for the JVM to execute
 
Terrance Samson
Ranch Hand
Posts: 102
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that's the weird thing about it: I know a JAR file is technically just a normal document or file like any other, and gets run by an interpreter, which gives meaning to it, but I'm telling you, when I tried to run it by double-clicking, it said that I don't have execute permission set to it, implying that it needs to be executable to work properly.  Check this link if you want to see what I mean:

https://itsfoss.com/run-jar-file-ubuntu-linux
 
Sheriff
Posts: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:You cannot execute a JAR without a Java runtime program (JVM). An "executable" JAR is one where you can say:


It's java -jar myExecutable.jar. If you use -classpath you must still define the main class in the command.

(I assume the Main is a typo)
 
Terrance Samson
Ranch Hand
Posts: 102
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I'm not sure about that, but all I know about it is that when I use Eclipse, I have an option to make a "runnable JAR" file, and once I've created it, I can double-click it and it runs the program that I made (that's in Windows, but I would think it would work the same way in Linux, or could be made to work that way).
 
Marshal
Posts: 25930
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Terrance Samson wrote:I can double-click it and it runs the program that I made (that's in Windows, but I would think it would work the same way in Linux, or could be made to work that way).



Even in Windows you sometimes have to do something to make the JVM be the application which is associated with the .jar extension. I would assume that maybe there's a similar step required in Unix?
 
Terrance Samson
Ranch Hand
Posts: 102
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't mean to imply that there wouldn't be, but just that ultimately it should be possible to open programs by double-clicking them rather than necessarily having to type in a command every time.  But in any case, I think that issue should be taken care of soon.  I should be able to test it tomorrow.
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Tim Holloway wrote:You cannot execute a JAR without a Java runtime program (JVM). An "executable" JAR is one where you can say:


It's java -jar myExecutable.jar. If you use -classpath you must still define the main class in the command.

(I assume the Main is a typo)



Thanks. That's what I was remembering, but I checked to make sure and didn't see that option. Time for new glasses.

And no, "main class" was not a typo. It's the class containing Main, but it isn't (usually) named literally Main.
 
Tim Holloway
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Terrance Samson wrote:I can double-click it and it runs the program that I made (that's in Windows, but I would think it would work the same way in Linux, or could be made to work that way).



Even in Windows you sometimes have to do something to make the JVM be the application which is associated with the .jar extension. I would assume that maybe there's a similar step required in Unix?



Correct. In Windows, the Registry associates a filename extension with a command fod desktop execution.

In Linux and Unix (e.g.,MacOS) the process is a bit messier, though. since they are multi-user OS's and different users might have different click preferences. PLUS unlike Windows, where the desktop is an integral part of the OS, in the *n*x world there are many different desktop programs to choose from and many different desktop GUI file explorers. For example, Gnome and KDE desktops and Nautilus, Dolphin and Konqueror file explorers.

There is, alas, no common standard on how these different apps map double-clicks, just occasional voluntary collaborations. So it's best to check the documentation for the desktop and explorer(s) that you want to target. You will need, however, to define the precise command line, though, not just the program name. So, for example: "/usr/java/latest/java/bin/java -jar %U" would be what I'd set for Cinnamon Desktop.
 
Terrance Samson
Ranch Hand
Posts: 102
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I may not necessarily use the latest version of Java because I might need 8 for compatibility.  Also, I don't know what %U means.  In any case, there will only be one user account for this, so that shouldn't be an issue, and yes I'm using the newest version of Cinnamon included with Mint 20.
 
Let's go to the waterfront with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic