开发者

Continue execution in console after running jar

I have a jar that executes endlessly because i create a thread and the i join() the edt with this thread.

If i run this jar with double click on lets say windows a javaw process is created that runs forever and i can continue working which is what i want.

Now if i try to run the jar from cmd with java -jar myJar.jar the execution halts right there. What i want is to continue开发者_StackOverflow社区 cmd execution after running the jar.

*Note:*I currently trying to do this in linux console which i access with putty.So please consider this in your answer

Thank you


java -jar myJar.jar &

The & puts the command into the background and allows you to do other things from the shell prompt.

This is very basic UNIX/Linux shell stuff. I suggest that you find / read an online tutorial or a book on the shell you are using (e.g. bash). It will make your life a lot easier. Or if you are a masochist, read man bash.

I currently trying to do this in linux console which i access with putty.

Use of putty is actually not relevant.


Try this

java -jar myJar.jar&

It means that the process gets launched and runs in the background. If you want to get it back, type fg. To push it back in the background, press CTRL+Z (this pauses its execution and gives you back your shell prompt) and then run bg to resume it in the background.


Just run it as

java -jar myJar.jar &

The & will put the command into the background, where it happily runs. Just a basic Unix shell feature.


I personally prefer using screen. Because you can even define a session ID and restore them really easy.

You can start the jar with the following command:

screen -m -d java -jar myJar.jar

With the following command you can list all current sessions:

screen -ls

You can reopen a session with:

screen -r PID/Sessionname


Undeleted this answer after the OP last comment - it's not an answer to the written question but an additional answer to his actual problem


On windows, try

start java -jar myJar.jar

Reference: MS-DOS start command

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜