Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Runtime.getRuntime().exec释放/更改一些参数_Java_Eclipse_Maven_Eclipse Plugin - Fatal编程技术网

Java Runtime.getRuntime().exec释放/更改一些参数

Java Runtime.getRuntime().exec释放/更改一些参数,java,eclipse,maven,eclipse-plugin,Java,Eclipse,Maven,Eclipse Plugin,(-Dexec.mainClass=maven.mainClass变为maven.mainClass) 在Java()中使用maven执行Java类时 -Dexec.mainClass=maven.mainClass变为maven.mainClass package maven; public class MainClass { public static void main(String[] args) { System.out.println("app is run

-Dexec.mainClass=maven.mainClass
变为
maven.mainClass

在Java()中使用maven执行Java类时
-Dexec.mainClass=maven.mainClass
变为
maven.mainClass

package maven;

public class MainClass {
    public static void main(String[] args) {
        System.out.println("app is running!");
    }
}
从Eclipse使用

    Process p = DebugPlugin.exec(cmds, workingPath, envp);
    RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, MavenConstants.PROCESS_MESSAGE);
p=Runtime.getRuntime().exec(cmdLine,envp)只调用Java

 p= Runtime.getRuntime().exec(cmdLine, envp);
串接的字符串数组看起来像下面的字符串,不知何故松开了
-Dexec.mainClass=
部分

D:\Code\springsource\3.0\apache-maven-3.0.3\bin\mvn.bat compile exec:java -Dexec.mainClass=maven.MainClass 
输出

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building org.example.maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.672s
[INFO] Finished at: Fri Jan 24 23:59:50 CST 2014
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "maven.MainClass". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

发现
cmdLine.add(“-Dmaven.test.skip=true”)
也会变成just
true
,并出现类似的错误

我注意到JavaDoc中没有提到
Runtime.getRuntime().exec(

通过将所有选项放在一个字符串中解决

    cmdLine.add(mavenPath);
    cmdLine.add(mavenOptions+" compile exec:java -Dexec.mainClass="+packageClass);
    cmdLine.add(mavenPath);
    cmdLine.add(mavenOptions+" compile exec:java -Dexec.mainClass="+packageClass);