从运行的JAR执行批处理文件给出路径未找到错误 [英] Executing batch file from runnable jar gives path not found error

查看:519
本文介绍了从运行的JAR执行批处理文件给出路径未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行从Java程序的批处理文件。
当我从Eclipse中执行它工作正常,但当我让它运行的JAR它不能找到批处理文件的路径

I am executing a batch file from java program. When I execute from eclipse it works fine but when I make it a runnable jar it is not able to find the path of the batch file

我不停的批处理文件作为源目录的资源。
当我打印使用Class.getResource的资源的路径(/资源/ mybat.bat),它给出了正确的路径为

I kept the batch file as a resource in the source directory. When I print the path of the resource using Class.getResource("/resource/mybat.bat") it gives the path correctly as


  • 资源/ mybat.bat (JAR创建选项:包所需的库在生成JAR)

  • 文件:/ C:/Users/aasha.medhi/Desktop/myjar.jar /resources/mybat.bat (JAR创建选项:提取需要的库成生成JAR)

如果我提取罐,资源文件夹中。

If I extract the jar, the resources folder exist.

然而,当我尝试运行jar,它给系统找不到指定的路径错误的批处理文件

However when I try to run the jar, it gives "The system cant find the path specified error" for the batch file

我经历的大部分环节消失了,尝试了不同的选择,但没有任何运气。
我只是需要一种方法来创建可运行罐子properly.Please帮助..

I have gone through most of the links and tried out different options but without any luck. I just need a way to create the runnable jar properly.Please help..

推荐答案

而Java可以阅读JAR和对待他们就像普通的文件系统中,大多数其他应用程序不能。在这种情况下 CMD 不能。你必须批量解压到一个临时位置并从那里运行它。

While Java can read JARs and treat them just as the normal file system, most other applications cannot. In this case cmd can't. You have to extract the batch to a temporary location and run it from there.

这篇关于从运行的JAR执行批处理文件给出路径未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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