#run JAR file with BAT

1 messages ยท Page 1 of 1 (latest)

fluid siren
icy solarBOT
#

<@&987246399047479336> please have a look, thanks.

icy solarBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

fluid siren
#

Opening with independent cmd window:

buoyant tusk
fluid siren
buoyant tusk
fluid siren
#

It works when i open a new terminal, and then type "java -jar PATH_TO_FILE.jar", but don't work when i try to put inside a bat file

buoyant tusk
#

which error do you get ?

fluid siren
#

Example:
inside the bat file:

java -jar target/knightstour.jar
PAUSE

Open and closes.

=-=-=-=-=-=-=-=

new terminal window:
"java -jar "C:\Users\User\Desktop\knightstour\knightstour.jar""

Works fine

buoyant tusk
#

open a terminal window

#

run the bat

#

tell me the error

fluid siren
#

ok

#

Works fine... That's weird...

#

It doesn't work only when I click to run

#

Apparently, when I click to play, it opens a new terminal on the sys32 folder

#

and tries to locate the jar inside this folder, but, of course, it fails

#

but when i specify the path it works fine

buoyant tusk
vague anvil
#

Maybe because you're starting as administrator?

buoyant tusk
#

i saw it opening in the correct folder

fluid siren
fluid siren
vague anvil
#

I didn't see the video before, Alathreon is correct

buoyant tusk
#

๐Ÿค”

vague anvil
#

It does open in the right folder

buoyant tusk
#

weird

#

sometime it opens the right folder

vague anvil
#

The system32 is just where CMD lives

buoyant tusk
#

at the start of the video

fluid siren
#

i'm confused ๐Ÿ˜†

#

i'll just format my pc

#

too much logic

#

Better video ๐Ÿ‘‡ ๐Ÿ‘‡

buoyant tusk
#

so weird

#

try start java -jar...

fluid siren
#

Nope..

buoyant tusk
fluid siren
#

opens another terminal then closes

buoyant tusk
#

what

fluid siren
#

Yeah.. ๐Ÿ˜†

#

No programming challenge will defeat this one

true whale
#

please share the jar

buoyant tusk
true whale
#

why do u have start in ur bat?

#

remove that

buoyant tusk
#

to see if creating a cmd will still cause the same problem

fluid siren
true whale
#

fair. shouldn't be there

#

start will create another cmd and that one has no pause in it

#

hence the double window

fluid siren
#

I could send the github repository, but I think it wouldn't help

buoyant tusk
true whale
#

opens another terminal then closes

its the cause of that issue. that's what i was replying to. cheers Wavey

buoyant tusk
true whale
#

yeah but u can't read the error without a pause

buoyant tusk
#

and the pause doesn't work

true whale
#

the pause is not applying to the window created by start

fluid siren
buoyant tusk
true whale
#

start "java -jar Foo.jar & pause"

#

or just without start

buoyant tusk
true whale
#

im not sure why u want to keep discussing this with me. can i leave? lol

#

u got this Wavey

fluid siren
#

You can go, guys. Thank's for your support

#

I'll keep searching this

buoyant tusk
#

when he is running the bat from a terminal, it works
but when he is running by double clicking, it doesn't and immediately close

buoyant tusk
#

which shouldn't happen

true whale
#

and uve checked that the jar doesn't run a new Process(...)?

fluid siren
#

It doesn't run a new process. It's a simple unfinished game

vague anvil
#

Can you share the source

fluid siren
#

But forget...

vague anvil
#

Just in case it's something there

fluid siren
#

This is getting too big hahah

#

ok

true whale
#

well. this is easy to debug locally as u shared the jar file

#

im on mobile, so I'm out

vague anvil
#

Probably a private repo, gives me a 404 ๐Ÿ˜›

fluid siren
#

1 sec

true whale
#

comment out the print in the clear console method

#

then try again

fluid siren
#

Ok

#

1 sec

#

Omg

#

lol

#

hahahhahah

#

worked

#

thanks

#

๐Ÿ˜† ๐Ÿ‘

true whale
#

๐Ÿ‘

fluid siren
#

clearConsole() was the problem. Problem solved lol

true whale
#

those ansi commands are interpreted differently per console

#

the first command u had there is supposed to move the cursor at top left and the second is supposed to clear everything from cursor to current print position

#

resulting in a clear

#

but seems that cmd just messed it up completely and closes

vague anvil
#

Still weird that it closed the window though

true whale
#

because cmd is just bad with ansi

vague anvil
#

I think it gets some support in more recent versions

#

But maybe that's bugged here

true whale
#

unsure. maybe powershell behaves better

fluid siren
#

Didn't think about that..

#

I'll try to create a new method to do that

true whale
#

afaik cmd has no proper way to clear

vague anvil
#

cls

true whale
#

yeah but no ansi

#

have fun triggering cls from within Java

fluid siren
#
public final static void clearConsole()
{
    try
    {
        final String os = System.getProperty("os.name");
        
        if (os.contains("Windows"))
        {
            Runtime.getRuntime().exec("cls");
        }
        else
        {
            Runtime.getRuntime().exec("clear");
        }
    }
    catch (final Exception e)
    {
        //  Handle any exceptions.
    }
}

I've seen this in Stack.. But this "exec" method is outdated afaik

icy solarBOT
fluid siren
#

Thank you, guys.

true whale
#

ur welcome