在Java中执行jar文件 [英] Executing jar file in java

查看:81
本文介绍了在Java中执行jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java执行jar文件.到目前为止,我的代码运行良好.

i'm executing a jar file in java. so far my code works perfectly.

因为它是一个控制台应用程序,所以通过Java执行epubcheck

im executing epubcheck via java because its a console application

这是epubcheck的地址

here is the address of the epubcheck

https://github.com/IDPF/epubcheck

除非我需要浏览的文件名包含 ' 标志 文件夹名称上的空格或文件名上的空格.

except when the name of the file that i need to browse contains ' sign and space on the folder name or space on the file name.

这是文件夹名称错误

Unrecognized argument: 'Files\1.epub'

当文件名包含'

Unrecognized argument: 'the'

这是我的代码

String a = System.getProperty("user.dir") + "\\epubcheck-4.0.1\\" + "epubcheck.jar";
    Process p = Runtime.getRuntime().exec("java -jar" + " " + a + " " + selectedFile.getAbsolutePath());

这是运行epubchecker的方法

here is how to run the epubchecker

java -jar epubcheck.jar file.epub

但是当我在命令提示符下手动运行它时,并没有给我一个错误

but when i run it on command prompt manually it didn't give me an error

推荐答案

您应该引用组成命令行的令牌.使用.exec(String[])版本

You should quote the tokens that make up your command line. Use the .exec(String[]) version

Runtime.getRuntime().exec(new String[]{"java"
     , "-jar"
     , a
     , selectedFile.getAbsolutePath()});

这篇关于在Java中执行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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