从exec-maven-plugin调用源代码

时间:2016-06-13 11:22:51

标签: maven exec-maven-plugin

我目前正在尝试在从exec-maven-plugin调用的shell脚本中为测试设置一些环境变量。插件声明如下所示:

<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <version>1.5.1-SNAPSHOT</version>
    <executions>
        <execution>
            <id>Database start</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>source</executable>
                <arguments>
                    <argument>${basedir}/src/main/scripts/setenv.sh</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>

为了在主进程中获取环境变量,我使用了source。虽然脚本本身可以成功调用(通过将其设置为可执行文件,而不是像上面那样,作为参数和源代码可执行),但使用source的调用不成功:

java.io.IOException: Cannot run program "source" (in directory "/home/reichelt/workspaces/irpsimworkspace/backend/backend-server"): error=2, Datei oder Verzeichnis nicht gefunden
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at java.lang.Runtime.exec(Runtime.java:620)
    at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:61)
    at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:279)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:336)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:760)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:703)
    at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:295)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.io.IOException: error=2, Datei oder Verzeichnis nicht gefunden
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 30 more

原因似乎是exec-maven插件使用Apache Commons Exec(https://github.com/mojohaus/exec-maven-plugin)。 Apache Commons Exec仅搜索可执行文件,并且由于源不是可执行文件而是shell命令,因此无法在此处调用它。

有没有办法让环境变量在脚本之外设置?

0 个答案:

没有答案