2
我想共享2個模塊A和B之間的測試資源。在測試資源中,我有一些文件的目錄。像這樣在模塊之間共享測試資源問題
-dir
----f1
----f2
我都根據Share test resources between maven projects完成。現在從B測試中,我可以使用如下語法訪問資源:
this.getClass().getClassLoader().getResource("dir/f1")
而且它工作得很好。但我不想核心所有文件名,如f1
或f2
。我真正想要的是從目錄中獲取所有文件。像
File foo = new File(this.getClass().getClassLoader().getResource("dir").getFile());
assert foo.isDirectory()
foo.list()
...
但是當我創造這樣的方式FOO它甚至不存在(foo.exist()
返回false)。
我該如何處理?
更新。替代的解決方案使用Ant
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<configuration>
<target>
<fileset id="d" dir="${basedir}/src/test/resources/dir" includes="*"/>
<pathconvert property="d" refid="d">
<map from="${basedir}/src/test/resources/" to=""/>
</pathconvert>
<touch file="${basedir}/src/test/resources/d/listOfCharts.txt"/>
<echo file="${basedir}/src/test/resources/d/listOfCharts.txt" message="${charts}"/>
</target>
</configuration>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
謝謝,我會看看這個方法。 – 2012-01-12 15:08:10
它看起來不錯。但是我決定爲它使用'maven-antrun-plugin'。如果您有興趣,請參閱更新的答案。 – 2012-01-12 16:30:58