Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 389 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Starting Java app from cmd works, from batch not

#1
The Problem is as follows:
I have a Java Application packed in a ".jar"-File.

I can start the App (Swing Application) by either

- doubleclick on the jarfile
- commandline `java -jar MyApp.jar`

However when I put the commandline command into a batchfile, it will tell me
> Unable to access jarfile MyApp.jar

The batch file is in the same directory as the jar. Just where I also started from cmd-line.
I tried to call the bat with Administrator-rights and from an admin-shell - no effect.

I'm working on a Windows 7 (64bit) machine. Any hints will be appreciated.

EDIT

You asked for it :) Here is the batch file:

@ECHO OFF
java -jar MyApp.jar
@PAUSE

EDIT 2

Invoking the batch by double-click and from cmd has the same effect.
Changing the command to

java -jar "C:\Full\Path\MyApp.jar"

has no effect.

EDIT 3

I added `SET Path=%Path%;C:\Path\To\Jar` to the batchfile. No effect.
I also tried using double backslashes as suggested by Chris' link and supported by Viruzzo. Also no effect.
Reply

#2
When you double click on .bat file, the working directory is *not* set to where the .bat file is, but is usually something like %AppData%. To make it work you need to put the full path to the file inside the bat (i.e. `java -jar C:\path\to\jar\MyApp.jar`).
Reply

#3
Make sure you don't have the hide extension option enabled in windows. Maybe the name of your jar ends with .jar.jar? Are you sure the path to the jar is correct?
Reply

#4
This isn't the answer to your specific problem, but this will allow you to troubleshoot the problem so you will find an answer. Adding a sleep command will let the command prompt sit, so it doesn't close right away.

ping 1.1.1.1 -n 1 -w 10000

(sleep for 10 seconds)
Reply

#5
I havent't yet figured out why, but now it works:

The first batchfile was a copy of another and I just changed the contents to fit my needs.

**NOW I renamed it to MyApp.bak and wrote a new MyApp.bat from scratch.**

As soon as I find out, what the difference was, I'll update this answer.

**UPDATE**

It happened again with another batch. This time, we got the reason: For some reason, the batch file did not inherit rights when copied. Creating a new one in the folder had the correct rights. So, in the end it was indeed a rights-issue.
Reply

#6
I just had to put my path in quotes, even though it had no spaces or odd characters.

`java -jar C:\Users\Jacob\executables\some-file.jar` failed, but

`java -jar "C:\Users\JStamm\executables\some-file.jar"` worked.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through