从不同目录启动jar文件 [英] Launching jar file from different directory

查看:76
本文介绍了从不同目录启动jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在处理一些相当简单的信息。我尽可能地为谷歌做了一些努力,但我似乎没有任何进展。



基本上,我有一个需要启动的系统来自与当前工作目录不同的目录中的JAR文件。在Windows下,从命令提示符,这是我试图工作的命令行:



Hi all,

I'm after some fairly trivial information. I've put in some good effort to Google as much as possible but I don't seem to be getting anywhere.

Essentially, I have a system which requires launching a JAR file from a different directory than the current working directory. Under Windows, from command prompt, this is the command line I'm attempting to get working:

C:\a\b\c>java -Djava.library.path=. -jar C:\x\y\z\name.jar





但是这不会保留当前的工作目录。而是将工作目录更改为C:\ x \\\\ z。这是我不想发生的行为,我需要当前的工作目录来保留调用命令的目录。



我得到的一些结果遇到过这种情况应该是这样的。 Java应该保留父进程的工作目录(在这种情况下,命令提示符)但是我发现这不起作用。



我需要特别要保留当前的工作目录吗?



谢谢



我有什么试过:



用Google搜索保留工作目录的答案。

尝试使用不同参数的Java命令行的许多不同组合。



However this does not retain the current working directory. Instead, the working directory is changed to "C:\x\y\z". This is behaviour which I don't want to happen, I need the current working directory to remain the directory where the command was called from.

The few results I have come across have specified that this should be the case. Java should retain the working directory of the parent process (in this case, the command prompt) however I'm finding this doesn't work.

Do I need to do anything in particular to retain the current working directory?

Thanks

What I have tried:

Googled answers for retaining working directory.
Attempted many different combinations of the Java command line with different parameters.

推荐答案

我设法通过使用class-path命令行代替-jar参数来实现此功能。为了实现这个目的,我使用了:



I managed to get this working by using the class-path command line in place of the -jar argument. In order to get this working I used:

C:\a\b\c>java -cp "C:\x\y\z.name.jar";lib\* path.to.main.Class





感谢Mohibur Ra​​shid提供方向!



Thanks to Mohibur Rashid for providing the direction!


这篇关于从不同目录启动jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆