• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Compiled jar file not running

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, me again. I realise you may think this is a repost however I've not found anything which is similar to my issue.

I'm using IntelliJIDEA to code a simple hello world program with a user input (to keep the dialog open so I know if it's worked).

Currently the code is:


Apologies to the admins, I know you've set my code to be formatted differently on other posts but I'm unsure which setting you use!

Anyway, I run the .jar file and nothing happens. No error message, no dialog box, no command line, nothing. So I'm unsure what the issue is. It runs absolutely fine in IntelliJ, and when I run it on the CMD it runs fine, but not when I double click the .jar file. Unfortunately, with what I have planned, theres no way the end users will use the command line every time to run a program.

Thanks,
James
 
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I'm understanding you correctly, you can run your program in a cmd window but not by double clicking the .jar file.

In these cases  I make a batch file (.bat) and put the commands into that then you'd run it by double clicking the .bat file. Additionally you can then create a short cut to the .bat file which would give you a desktop icon. (I'm assuming you're on Windows here.)
 
James Ritchie
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carey,

Brilliant idea, I might use that in the meantime. Would the next step be to maybe make a custom installer that can save the .jar and .bat locally and create a shortcut to the batch file on their desktop for example?
 
Carey Brown
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Ritchie wrote:Hi Carey,

Brilliant idea, I might use that in the meantime. Would the next step be to maybe make a custom installer that can save the .jar and .bat locally and create a shortcut to the batch file on their desktop for example?


I make two directories that default to being under C:\
C:\<myname>
C:\<myname>\bin\<all project .bat files>   ** only one that needs to go into PATH
C:\<myname>\<myprogram>\<all .jars and support files except .bat>

C:\<myname-data>
C:\<myname-data>\<myprogram>\<all writeable files>

I make two environment variables:
myname_HOME
myname-DATA_HOME

So that if they  need to be installed somewhere other than C:\
Also these can be used in the PATH.

This arrangement will support multiple programs.
 
Master Rancher
Posts: 180
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Carey
Better option would be inside user.home instead of root of system partition.

@OP
Well, to me it seems you misinderstand how Java works on windows (or how CLI and GUI differ in general).
What you've written is what's known as a CLI (command line interface) type programm: It requires the user to start it from a command prompt.
What you may think should happen when you double click on your jar: A command prompt opens, prints hello world and waits for an input.
What actually happens: Your jar is run by javaw.exe which is intended for GUI type applications and does NOT open a command prompt. If you're lucky it shuts down as System.in is either EOF or null and hence doesn't wait on an input that never happens ... in the worst case you keep starting new instances all waiting in the background for some input. Check your taskmanager if you have running javaw.exe processes.

If you want an application that works by double clicking on it you need to use some GUI like Swing. Otherwise if you want to stay at the cli level you have to launch it from cmd or any other terminal.
 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Bendford wrote:What actually happens: Your jar is run by javaw.exe which is intended for GUI type applications and does NOT open a command prompt.



It's possible to modify the action taken by double-clicking a JAR file to have it run java.exe instead of javaw.exe; at least it used to be possible to do that. Most likely it still is, but I couldn't tell you how to do it because Windows has redesigned the things which give you access to that sort of maintenance at least three times since I last did it. But a bit of web searching might lead you to an explanation which works now.
 
Carey Brown
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Bendford wrote:@Carey
Better option would be inside user.home instead of root of system partition.


Easy enough to do with the environment variables point to wherever you put it.
 
Matthew Bendford
Master Rancher
Posts: 180
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul
I agree with you it's possible to change, I would do it in registry as at least this way hasn't changed (yet). But to me it's the kind of "solution" to tinker with symptoms instead of "curing" the cause, which seems to me as a misunderstanding of CLI vs GUI.

@Carey
True, but that's what led to Vista and its "beloved" UAC: It was microsofts attempt to implement what's default on unix since the 60s: A regular user only has write access within user.home. Any other system wide changes require active administrator grant. But the Windows ecom system being itself: Most devs got "creative" by changing permissions to the program folder to writeable by all. Some even modified Program Files and Windows and by this completely bypassed UAC. Why? Because Windows first grew up without any filesystem level permissions and so did its users.
Hence recommending the root of the system volume is not a good idea and can lead to permission issues or crashing the system (yea, I too once fell for the famous "rm -rf /").
 
Carey Brown
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Bendford wrote:@Carey True, but


I'm not arguing with you. You have a valid point. I was conveying a technique I use in a quick paragraph, if you'd like to offer up a longer description of how you'd solve the OP's problem I'm all ears. I think to describe fully the headaches of distributing, installing and running Java programs in Windows would take more than a page.
 
Saloon Keeper
Posts: 24493
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Windows Registry is an awful place to store settings.

But enough of the Windows Registry in general - it's an especially bad place to store settings for Java applications, because it's not a "write-once/run-anywhere" sort of resource.

Java does have its own preferences system modeled after how Unix/Linux does it. Traditionally, that would be that per-user preferences would go under a hidden directory under the user.home directory, although the sheer volume of such directories has led to an alternate convention ($HOME/.local/share/app-preferences directory) becoming popular. You can also define environment variables for the command shell at the per-user or per-system level via the Windows Control Panel applet.

Finally, you can simply define them as command-line options:

java -jar binks_jar.jar -Dmyname_HOME=%HOME% -Dmyname_data=%HOME%\data
 
Paul Clapham
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Bendford wrote:@Paul
I agree with you it's possible to change, I would do it in registry as at least this way hasn't changed (yet). But to me it's the kind of "solution" to tinker with symptoms instead of "curing" the cause, which seems to me as a misunderstanding of CLI vs GUI.



Agreed. It's worth clearing up that misunderstanding, which must be common among beginners. I may have made that change on my Windows machine at some time in the distant past but I doubt it... I haven't ever produced a JAR file containing a CLI application and I don't think that's a common thing to do.
 
Marshal
Posts: 3707
523
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Java does have its own preferences system ...


In a Windows environment, the Java user preferences are stored in the registry at: HKEY_CURRENT_USER\Software\JavaSoft\Prefs



 
Tim Holloway
Saloon Keeper
Posts: 24493
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see they finally fixed it.

Still don't recommend storing any preferences in the Registry, though. It's a lot harder to recover settings from a registry backup than it is from a file backup. Been there/did that.

Lest we forget - one of the primary reasons the Registry (F/K/A Registration Database) was created was during the era where file allocation units were sized based on the disk capacity and it was really painful to have 64K of disk space per file consumed for 20 files containing maybe 10 lines of text each. The registration database allowed compacting that information down efficiently at the expense of transparency.
 
Carey Brown
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Tim Holloway
Saloon Keeper
Posts: 24493
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought the current form was more like C:\users\%USERNAME%\data\appname\

But I not only don't run Windows, I don't have a Windows machine accessible to me, so I can't confirm.
 
Carey Brown
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I thought the current form was more like C:\users\%USERNAME%\data\appname\

But I not only don't run Windows, I don't have a Windows machine accessible to me, so I can't confirm.


You missed my previous responses. Tim suggested user.home, I did not. I said "you can put it in user home" but that's your choice but it doesn't matter if you've established your own environment variable "your-name_HOME". An environment variable such as this should also work for *nix.
 
Tim Holloway
Saloon Keeper
Posts: 24493
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The equivalent for Unix/Linux would be ${user.home}/.java/.userPrefs and it should be noted that the file format is XML and not property-file format. MacOS may have its own location - not sure.

Also note that the Java Properties system and Java Preferences systems are similar in many ways, but not - as you can see from the above - identical.
 
Carey Brown
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:But enough of the Windows Registry in general - it's an especially bad place to store settings for Java applications...

What are you talking about? You're mixing Java settings with program settings. Two different things. Program settings can be handled any way that the program would like to implement them, XML or otherwise.
 
Tim Holloway
Saloon Keeper
Posts: 24493
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now you've got me confused. I've been reading 2 types of configuration options here:

1. JVM and vendor-supplied utility options. Which, grudgingly, I will allow have their place in the registry.

2. Application options/preferences persistently stored, whether manually or (and/or) by the application itself.

I'm only interested in - and talking about - the latter, since the former are generally under the domain of the product installer and/or Windows control panel.

I don't like application options in the registry because, as I said, experience has taught me that recovering the little buggers if the Windows system has gone South can be a serious challenge. Restoring normal files is straightforward, but the registry is in an opaque format so unless your nightly backups include dumping the application options out to .reg files and saving them, getting settings recovered from a dead registry comes under the things-I-would-rather-not-attempt-in-an-emergency heading.
 
Paul Clapham
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question here is about the Windows setting which says "Which application should I run when you double-click in File Explorer on a file with extension .JAR?" Presumably that is stored in the registry somewhere but it's not necessary to edit the registry directly to modify it. To me it looks fairly straightforward to modify it from inside File Explorer.
 
Tim Holloway
Saloon Keeper
Posts: 24493
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:The question here is about the Windows setting which says "Which application should I run when you double-click in File Explorer on a file with extension .JAR?" Presumably that is stored in the registry somewhere but it's not necessary to edit the registry directly to modify it. To me it looks fairly straightforward to modify it from inside File Explorer.



You are correct. The Windows Registry contains a set of associations between file extensions and applications and that's how it knows to run Word when you click on a Word Document. Or "javaw" when you click on a JAR file. You can edit the registry directly, upload a ".reg" file or use the desktop to make the association.

Setting up a JAR file to run directly isn't usually that useful, however, since unless you're only going to make GUI java apps with no command line options, the program will want stdin/stdout/stderr and there's no place to put options on the command line on a per-icon basis (some other GUI OS's don't have that limitation). For such beasts, it's actually better to run the JAR as a command script and have the desktop launch the script, instead.
 
Paul Clapham
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Setting up a JAR file to run directly isn't usually that useful, however, since unless you're only going to make GUI java apps with no command line options, the program will want stdin/stdout/stderr and there's no place to put options on the command line on a per-icon basis (some other GUI OS's don't have that limitation). For such beasts, it's actually better to run the JAR as a command script and have the desktop launch the script, instead.



Yes, lately I have just been creating shortcuts to do that.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic