maven basedir - 用frontslash替换反斜杠

时间:2015-03-23 12:18:19

标签: java maven

我怎么能用一个\替换我的basedir到一个带有\\?

的basedir

我试过了:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                <skinnyWars>true</skinnyWars>
                <version>6</version>
                <modules>
                    <webModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>ecad-application-ws-webservice</artifactId>
                        <bundleFileName>ecad-application-ws-webservice.war</bundleFileName>
                        <contextRoot>/ecad-ws/ecadservice</contextRoot>
                    </webModule>
                </modules>

               <source>
                    project.properties['basedir']=project.properties['basedir'].replace('\\','/');
               </source>
            </configuration>
        </plugin>

但这并没有改变任何事情......任何人都有其他想法吗?

2 个答案:

答案 0 :(得分:4)

我已经习惯了groovy插件来解决它:

<plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <executions>
              <execution>
                <id>set-unixy_build_directory!</id>
                <phase>compile</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <classpath>
                    <element>
                      <groupId>commons-lang</groupId>
                      <artifactId>commons-lang</artifactId>
                      <version>2.4</version>
                     </element>
                  </classpath>
                  <source>
                    if (org.apache.commons.lang.SystemUtils.IS_OS_WINDOWS) {
                      project.properties.myDynamicProperty =
                      project.basedir.absolutePath.replace('\\','\\\\');
                    }
                  </source>
                </configuration>
              </execution>
            </executions>
        </plugin>

答案 1 :(得分:1)

你能看看以下是否有效吗?

替换

project.properties [&#39; BASEDIR&#39;] = project.properties [&#39; BASEDIR&#39]。代替(&#39; \&#39;&#39; /&# 39);

pom.properties [&#39; main.basedir&#39;] = project.parent.basedir.absolutePath.replace(&#39; \&#39;&#39; /&#39);