2013-08-22 57 views
-1

我正在使用com.github.goldin提供的copy-maven-plugin。我想通過Maven複製一些文件。使用Maven添加根路徑

但是,我不想硬編碼路徑,因爲驅動器會有所不同。例如:

<build> 
    <plugins> 
    <plugin> 
     <groupId>com.github.goldin</groupId> 
     <artifactId>copy-maven-plugin</artifactId> 
     <version>0.2.5</version> 
     <executions> 
     <execution> 
      <id>create-archive</id> 
      <phase>test</phase> 
      <goals> 
      <goal>copy</goal> 
      </goals> 
      <configuration> 
      <resources> 
       <resource> 
       <targetPath>/../src/Server-Parent/src/test/resources</targetPath> 
       <file>/../src/Server-Parent/DB/src/test/resources/mongoDB.xml</file> 
       <destFileName>mongoDB.xml</destFileName> 
       </resource> 
      </resources> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

當我硬編碼,例如,C:\folder name\src\Server-Parent\src\test\resources從任何Maven項目完美的作品。然而,只要我把../src/../src它包含問題。

任何想法如何解決這個問題?

[ERROR] Failed to execute goal com.github.goldin:copy-maven-plugin:0.2.5:copy (c reate-archive) on project Server-Parent: Processing <resource> [Target p ath(s) [/../src/Server-Parent/src/test/resources], directory [C:/folder name\src/Server-Parent/DB/src/test/resources], dependencies []] fa iled with [java.lang.AssertionError]: [C:\folder name\src\Server-Parent\DB\sr c\test\resources] does not exist. Expression: d.directory -> [Help 1] [ERROR] 

編輯2:

我試圖才達到:

我有服務器單親這是含POM值的pom.xml。在這裏面是另一個包含pom.xml pom值的Server-SubParent。現在裏面是包含jar的Server-SubFunctionality。

Accoriding到你的答案這可怎麼achived:

$ {} project.basedir

這三個項目中的服務器SubParent是服務器家長的模塊,但服務器SubParent是另一個包含另一個包含真實功能的模塊。

Server-Parent 

<modelVersion>4.0.0</modelVersion> 
<artifactId>Server-Parent</artifactId> 
<packaging>pom</packaging> 

<name>Server-Parent</name> 

<modules> 
<module>Server-Sub-Parent</module> 
</modules> 

Server-SubParent 

<modelVersion>4.0.0</modelVersion> 

    <parent> 
<groupId>com.server</groupId> 
<artifactId>Server-Parent</artifactId> 
<version>S06B1-RELEASE</version> 
</parent> 

<artifactId>Server-Sub-Parent</artifactId> 
<packaging>pom</packaging> 

<name>Server-Sub-Parent</name> 

<modules> 
<module>Server-Sub-ParentFunctionality</module> 
</modules> 

Server-Sub-Parent-Functionality 

<parent> 
<groupId>com.server</groupId> 
<artifactId>Server-Sub-Parent</artifactId> 
<version>S06B1-RELEASE</version> 
</parent> 

<artifactId>Server-Sub-Parent-Functionality</artifactId> 
<packaging>jar</packaging> 

<name>Server-Sub-Parent-Functionality</name> 
+1

'它包含的問題。' *有什麼問題?* – 2013-08-22 13:40:42

+1

'/../ src /'不是一個有效的路徑構造,不在任何我知道的操作系統上,特別是在Windows上。實際的錯誤是什麼,否則這個錯誤會被拒絕投票並且很快關閉。 –

+0

請參閱上面的修改。 – user1646481

回答

0

嘗試使用maven預定義變量。

<resource> 
       <targetPath>${project.basedir}/../src/Server-Parent/src/test/resources</targetPath> 
       <file>${project.basedir}/../src/Server-Parent/DB/src/test/resources/mongoDB.xml</file> 
       <destFileName>mongoDB.xml</destFileName> 
       </resource> 

一些有用的變量

${project.basedir} 
${project.build.directory} 
${project.build.sourceDirectory} 

更多信息here

+0

其實,我不想使用這種方法,因爲我在C:\某些文件夾和其他人不是。它可能是C:\某個文件夾2 – user1646481

+0

hmmm ...這些變量是相對於pom位置的。所以,不管你在哪裏路徑將保持不變 – WeMakeSoftware

+0

好吧,假設父項目是Server-Parent包含pom值作爲代表超級pom的pom.xml。然後在裏面有Maven項目的模塊。所以第一個是另一個名爲Server-SubParent的父節點。這是包含pom值的另一個pom.xml。現在最後一個階段是另一個包含jar的Server-SubFunctionality。你如何指定目錄結構作爲我想要做的? – user1646481