0

I am currently trying to set some environment variables for a test in an shell-script that is called from the exec-maven-plugin. The plugin declaration looks like this:

<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>

In order to get the environment variables in the main process, I used source. While the script itself can be called sucessfully (by setting it as executable, instead of, as above, as argument and source as executable), the call with source is not successfull:

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

The reason for this seems to be that exec-maven plugin uses Apache Commons Exec (https://github.com/mojohaus/exec-maven-plugin). Apache Commons Exec only searches for the executable, and as source isn't an executable but a shell command, it isn't possible to call it here.

Is there any way to get the environment variables set outside of the script anyway?

David Georg Reichelt
  • 963
  • 1
  • 15
  • 36
  • I don't now why you want to set environment variables, but goal `exec` starts separated process. So even if you find a way to launch `source` command, environment set up by setenv.sh will die when `exec` has completed – michaldo Jun 13 '16 at 11:37
  • Why are you using a SNAPSHOT version of the plugin? `1.5.1-SNAPSHOT` ? – khmarbaise Jun 13 '16 at 12:15
  • Take a look at the error message `Caused by: java.io.IOException: error=2, Datei oder Verzeichnis nicht gefunden` ? – khmarbaise Jun 13 '16 at 12:16
  • @khmarbaise I wanted to set some debug outputs in `ExecMojo.executeCommandLine`, to find maybe an easy way of making it possible to set environment variables, which didn't work out as there is no executable for source. I tried the same with 1.5.0. The error message appears as source isn't an executable file - but is there some other way of exporting the environment variables to the rest of the maven process? – David Georg Reichelt Jun 13 '16 at 13:50
  • It will be helpful if you clarify what you want to achieve finally. Environment variable is a means to an end – michaldo Jun 14 '16 at 05:39

0 Answers0