在工作中遇到了一个问题:
我在JAVA代码中调用一个执行脚本,比如xx.sh
String command = "sh xx.sh -w -k -c a.jar;b.jar......xxxx.jar myclass"
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
因为我在-c中加的jar包太多,所以在在执行的时候会报命令过长的错误:the command is too long.
试用了很多方法,费了好长时间。特写下来,以便查阅。
我的JAVA代码是在开发ECLIPSE插件的时候用到的。所以有些基于ECLIPSE的解决方法。
1 这个sh中最终也是调用了一个java类,所以我尝试了直接调用这个java类。两个途径:
一种是用classloader机制,利用反射,拿到这个java类,然后load起来,调用它的main方法。在我的java类里把那些长参数设进去。
可以解决,但工作量较大。需要去解析sh文件,拿到里面引用的jar,要不然sh里面的java类起不来。
一种是用eclipse的launch configuration,同样的问题。
2 用processbuilder
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new File(commandLocation));
Process proc = builder.start();
这个command是个list。
这种方法不行。还是太长。这是别人告诉的一个方法。
3 创建一个jar,把这些jar都加到它的menifest的class-path里,然后-c 后面只加这个jar就行了。恩,我就是这么解决的。
4 拿到这个sh,把我的所有jar都加到系统的classpath里面,或者创建一个新的sh去作这个工作。然后去跑它就行了。不过用这种方法需要有一个前提,就是sh里的那个Java类,它去load我给它的java类时,用的是classloader机制,这个classloader需要继承它的父classloader的classpath.
分享到:
相关推荐
在使用Intellij IDEA开发时,经常会遇到"Command line is too long"的错误信息,这个错误信息通常是在项目的构建或运行过程中出现的。这种错误信息的出现会导致项目无法正常运行,从而影响开发效率和项目的进度。 ...
ruby-destroyed_at, 用于安全销毁的ActiveRecord Mixin DestroyedAt 查找帮助?如果是一个 Bug ,请在GitHub上打开一个问题。安装将 destroyed_at gem 添加到 Gemfilegem 'destroyed_at'你可以在每个模块中
During the Core elections in 2002, Mark Murray stated “I am opposed to a long rule-book, as that satisfies lawyer-tendencies, and is counter to the technocentricity that the project so badly needs.”...
o Added /SaveDirect command line option, for using with the other save command-line options (/scomma, /stab, /sxml, and so on...) When you use the SaveDirect mode, the attachments list is saved ...
The side effect for this is that YOUR app must check if the host is a host name or a IP address, in my app I remove the periods and try to convert the result to a float (long integers don‘t work, ...
A 32-bit process is normally limited to addressing 2 gigabytes (GB) of memory, or 3 GB if the system was booted using the /3G boot switch even if there is more physical memory available. By leveraging...
The default value is 0.02: a command of -d.01 will override this with an error value of .01. In the run file, you specify a number of things. Look at demo.run in detail to see what they are; ...
If you're viewing this document online, you can click any of the topics below to link directly to that section. 1. Tutorial tips 2 2. Introducing the JavaMail API 3 3. Reviewing related ...
The code shown in the slide represents how the lock mode is stored internally. You can see these codes by querying the master.dbo.spt_values table: SELECT * FROM master.dbo.spt_values WHERE type = N'L...
- **line too long** (行太长): 汇编器对单行代码的长度有限制,当某一行超过这个长度时,会报此错误。 - **unmatched block nesting** (块嵌套不匹配): 如条件语句、循环等代码块的开始与结束不匹配。 - **...
9. line too long 行太长 该错误提示表示MASM编译器发现了行太长的代码,可能是由于编程错误或编译器配置错误等原因所致。 10. unmatched block nesting 不正确的区、段嵌套 该错误提示表示MASM编译器发现了不...
' Make the bDib() array point to the memory addresses: CopyMemory ByVal VarPtrArray(bDib()), VarPtr(tSA), 4 <br> <br>Now the bDib() array is a two dimensional array with the first ...
The only source of any storage location information is the sysindexes table, which keeps track of the address of the root page for every index, and the first IAM page for the index or table....
' Make the bDib() array point to the memory addresses: CopyMemory ByVal VarPtrArray(bDib()), VarPtr(tSA), 4 <br> <br>Now the bDib() array is a two dimensional array with the first ...
2. The Clipboard line is too long to paste - 剪贴板行太长无法粘贴 3. Network connection was refused by the server. - 网络连接被服务器拒绝 4. Wrong number of parameters. - 参数数量错误 5. instruction ...
#### line too long 行太长 - **行太长** 指单行代码超过了汇编器能够处理的最大长度。可以通过拆分长行成多行来解决。 #### unmatched block nesting 不正确的区、段嵌套 - **不正确的区、段嵌套** 当代码中...
* command line output is colored now (e.g. errors drawn in red) * MPEG2 1920x1088 bitstream is now automatically patched/cropped to 1920x1080 * log file now contains "<WARNING>" and "<ERROR>" ...
6. Too long source line(源代码行太长):源代码行长度超过编译器限制,最大为512个字符。 7. Hexadecimal constant without digits(十六进制常数无数字):发现十六进制常数的前缀0x 或 0X,但没有后随的十六...