Maven Exec Plugin : How configure the working directory

前端 未结 3 551
余生分开走
余生分开走 2021-01-04 02:28

I\'m using the Exec Maven plugin with the following command :

mvn exec:java

and I didn\'t manage to set the working dire

相关标签:
3条回答
  • If you like to set it via calling mvn exec:java ... you need to go via the property like this:

    mvn exec:java -Dexec.workingdir=Folder ...
    

    which has nothing to do what you defined in your pom cause calling the goal exec:java is not part of the life cycle.

    0 讨论(0)
  • 2021-01-04 02:59

    I couldn't either find a working fix, however an ugly workaround that was applicable in my case is to simply pass ${project.build.directory} (or any maven property for the matter) as an argument to the main class and handling it from there.

    <configuration>
        [...]
        <arguments>
            <argument>${project.build.directory}</argument>
        </arguments>
        [...]
    </configuration>
    

    Setting the current working directory inside the code to properly simulate the non-working workingDirectory configuration is a bit tricky if you insist doing so, check this linked answer for more information.

    0 讨论(0)
  • 2021-01-04 03:00

    I didn't found solution with exec:java.

    So, now I use exec:exec instead because we can set the workingDirectory and it' OK.

    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
        <execution>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration> 
        <executable>java</executable>
        <arguments>
            <argument>-classpath</argument> 
            <classpath />
            <argument>com.package.MyMainClass</argument>  
        </arguments>
        <workingDirectory>${project.build.outputDirectory}</workingDirectory>           
    </configuration>
    
    0 讨论(0)
提交回复
热议问题