• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't run java from a Windows .LNK file  RSS feed

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Moved to this new thread)

Stephan van Hulst wrote:Personally I think the most elegant solution is to distribute your application with a shortcut that uses a target 'java -jar <absolute path to jar>'. If you add the installation directory to the PATH, and your add the .lnk extension to the PATHEXT, you can run your application from anywhere by simply invoking the name of the shortcut.

This is exactly what is wrong. I used to do this all the time and it worked great, UNTIL Oracle's 8u45 release. Now it asks me which program I want to use to open the link (provided by Oracle) to java.exe.

In my shortcut properties my 'target' is set to: C:\ProgramData\Oracle\Java\javapath\java.exe -classpath c:\bin\app_finance\finance.jar;c:\bin\app_finance\libs\csbutils.jar;c:\bin\app_finance\libs\jcalendar-1.4.jar Finance

Note that 'java.exe' isn't really 'java.exe' but a link to it (not my doing, see Oracle).

Originally I didn't have ".LNK" in my PATHEXT but I added it and rebooted - same result.

Also tried just vanilla 'java.exe', but when I saved the shortcut and then reopened, the long form was back again.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Per Stephan's suggestion, I swapped out the Oracle link to java.exe to the actual path to the real java.exe. This worked, BUT, the whole point of Oracle's link is so that you don't have to constantly update your shortcuts (or whatever) when you install a new release of Java.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's just a limitation of shortcuts. You can't make shortcuts to shortcuts. The only solution left is to use a .bat instead of a .lnk:

java -classpath c:\bin\app_finance\finance.jar;c:\bin\app_finance\libs\csbutils.jar;c:\bin\app_finance\libs\jcalendar-1.4.jar Finance

or after declaring dependencies and entry point in the MANIFEST:

java -jar c:\bin\app_finance\finance.jar
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Well, that's just a limitation of shortcuts. You can't make shortcuts to shortcuts. The only solution left is to use a .bat instead of a .lnk:

java -classpath c:\bin\app_finance\finance.jar;c:\bin\app_finance\libs\csbutils.jar;c:\bin\app_finance\libs\jcalendar-1.4.jar Finance

or after declaring dependencies and entry point in the MANIFEST:

java -jar c:\bin\app_finance\finance.jar
Well, I've settled on the .bat approach but it leaves debris when using javaw instead of java, doesn't break anything, just ugly. By debris I mean, leaves the launching window running on the task bar which can be closed manually without affecting the running application, but I'd rather it not be there in the first place.

Example:
Desktop shortcut:
target: C:\Windows\System32\cmd.exe /K C:\bin\winclock.bat
BAT file:
C:\ProgramData\Oracle\Java\javapath\javaw.exe -jar c:\bin\app_winclock\winclock.jar

This was all a non-issue prior to Oracle's 8u45 release which deleted the java.exe (et al) from C:\windows\system32. I agree that having a 3rd party write to this directory is a no-no but it worked and my Java applications didn't have to change when a new version of Java was installed. So now we have this link to java.exe, which as you've stated, causes Windows grief because Windows doesn't support links to links.

So, to come full circle, I don't think Stephan's suggestion to use shortcuts to be workable and that .bat files are the way to go.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I tried it out, and I have absolutely no problem linking to the shortcut from my own shortcut. This is the target I use:

C:\ProgramData\Oracle\Java\javapath\javaw.exe -cp C:/Foo/foo.jar Foo

You need .lnk on the PATHEXT.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Actually I tried it out, and I have absolutely no problem linking to the shortcut from my own shortcut. This is the target I use:

C:\ProgramData\Oracle\Java\javapath\javaw.exe -cp C:/Foo/foo.jar Foo

You need .lnk on the PATHEXT.

Tried that and I get:

I'm running Windows 7 Ultimate
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eesh, I have no idea man. Can you try it on a different system?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try it on my W8.1 laptop later today and report back.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any luck?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The link to C:\ProgramData\Oracle\Java\javapath\javaw.exe appears to work on my Windows 8.1 laptop.

I'm left to wonder if it's a problem with all Windows 7 or if mine is missing something (?).
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:I'm left to wonder if it's a problem with all Windows 7 or if mine is missing something (?).
Tried it on a different laptop running W7 and it didn't work there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!