[英]How to create new directory in target folder with Maven
I am writing a library which will create a report based on the test results (imagine something like Surefire). 我正在编写一个库,它将根据测试结果创建一个报告(想象一下像Surefire这样的东西)。 And my problem is, I am able to create a folder in target/
directory to hold the report and also copy there necessary files but I can do that only when I build the library project itself. 我的问题是,我能够在target/
目录中创建一个文件夹来保存报告并复制必要的文件但我只能在构建库项目本身时才能这样做。
I would like to achieve same behavior like a Surefire plugin has, that means if I put dependency for my library to some project, let's say myProject
, then I will get something like myProject/target/myLibrary
after the build. 我希望像Surefire插件一样实现相同的行为,这意味着如果我将我的库的依赖项放到某个项目中,让我们说myProject
,那么我将在构建之后获得类似myProject/target/myLibrary
的内容。
btw, this is what I currently have 顺便说一句,这就是我现在拥有的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-test-sources</phase>
<configuration>
<tasks>
<echo message="Creating folder for the lib..." />
<mkdir dir="${report.folder}" />
<echo message="Copying Twitter Bootstrap libraries to the ${report.folder}" />
<copy todir="${report.folder}">
<fileset dir="src/main/resources/bootstrap">
<include name="**/**" />
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
And also bonus question, is there a variable for src/main/resources
? 还有奖金问题, src/main/resources
是否有变量?
Ok, so I found the solution which is using the getResourceAsStream()
method. 好的,所以我找到了使用getResourceAsStream()
方法的解决方案。
String classpathName = "/bootstrap/" + "css" + "/" + file;
InputStream inputStream = SetupReportDirectory.class.getResourceAsStream(classpathName);
String path = "target/myLibrary/bootstrap";
FileOutputStream outputStream = new FileOutputStream(path);
IOUtils.copy(inputStream, outputStream);
In your library, simply check if the target
directory (and/or whatever sub-directory you're interested in) exists. 在您的库中,只需检查target
目录(和/或您感兴趣的任何子目录)是否存在。 If it doesn't just use File.mkdirs(...)
and create it. 如果它不只是使用File.mkdirs(...)
并创建它。 That's what the maven-surefire-plugin
is doing. 这就是maven-surefire-plugin
正在做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.