You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Bidlo <pe...@gmail.com> on 2013/09/06 22:06:05 UTC

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). 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.

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.

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>

I also tried to execute this code inside my library
FileUtils.copyDirectoryToDirectory(new File("src/main/resources/bootstrap"),
new File("target/myLibrary") but I will get obvious FileNotFoundException -
bootstrap doesn't exist in the project which is using the library



--
View this message in context: http://maven.40175.n5.nabble.com/How-to-create-new-directory-in-target-folder-with-Maven-tp5769636.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to create new directory in target folder with Maven

Posted by Robert Scholte <rf...@apache.org>.
I found the related stackoverflow thread[1]. Let's continue there.

Robert

[1]  
http://stackoverflow.com/questions/18633956/how-to-create-new-directory-in-target-folder-with-maven

Op Sat, 07 Sep 2013 22:26:53 +0200 schreef Michael-O <19...@gmx.net>:

> Am 2013-09-07 22:21, schrieb Bidlo:
>> Sorry for that, I thought that this kind of problem can be resolved by  
>> some
>> other Maven plugin. And since it involves maven dependencies and project
>> building, I thought this a good place to ask (btw I asked on SO and I  
>> still
>> didn't get any answer)
>
> Always reference your first port of help. If you think you could solve  
> your problem with plugin (generic enough), you should do.
>
> If you just want to create a directory in the build directory, you Maven  
> Ant Plugin: <mkdir dir="${project.build.directory}/your-dir-goes -here"  
> />
>
> Have you already consulted:  
> http://maven.apache.org/plugin-developers/index.html?
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to create new directory in target folder with Maven

Posted by Michael-O <19...@gmx.net>.
Am 2013-09-07 22:21, schrieb Bidlo:
> Sorry for that, I thought that this kind of problem can be resolved by some
> other Maven plugin. And since it involves maven dependencies and project
> building, I thought this a good place to ask (btw I asked on SO and I still
> didn't get any answer)

Always reference your first port of help. If you think you could solve 
your problem with plugin (generic enough), you should do.

If you just want to create a directory in the build directory, you Maven 
Ant Plugin: <mkdir dir="${project.build.directory}/your-dir-goes -here" />

Have you already consulted: 
http://maven.apache.org/plugin-developers/index.html?

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to create new directory in target folder with Maven

Posted by Bidlo <pe...@gmail.com>.
Sorry for that, I thought that this kind of problem can be resolved by some
other Maven plugin. And since it involves maven dependencies and project
building, I thought this a good place to ask (btw I asked on SO and I still
didn't get any answer)



--
View this message in context: http://maven.40175.n5.nabble.com/How-to-create-new-directory-in-target-folder-with-Maven-tp5769636p5769697.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to create new directory in target folder with Maven

Posted by Michael-O <19...@gmx.net>.
Am 2013-09-07 20:56, schrieb Bidlo:
> Hello, thanks for answer.
>
> 1. It's a plain Java library
> 2. Not a Maven plugin
>
> Well, this is what I tried inside my library.
>
> File reportFolder = new File("target/myLibrary");
> reportFolder.mkdir(); //this creates folder in the project which is using
> the library, so far so good
> and then
> File foldersToBeCopiedFromMyLibrary = new
> File("src/main/resources/bootstrap"); //this is inside myLibrary project
> FileUtils.copyDirectoryToDirectory(foldersToBeCopiedFromMyLibrary,
> reportFolder);
>
> And this fails on FileNotFoundException because the project which is using
> myLibrary doesn't have bootstrap folder in src/main/resources. So I can
> actually create folder in the client project but I don't know how to copy
> files and folders from library project to it's client which is using it.
> (it's the same case like the Surefire does, it's copying CSS and JS files to
> the target/surefire dir in the client)

This does not look like a Maven problem. You are seeking help for a 
general Java problem. Go for stackoverflow.com.

This is clearly off-topics unless you are writing a Maven plugin and 
need some help.

Michael


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to create new directory in target folder with Maven

Posted by Bidlo <pe...@gmail.com>.
Hello, thanks for answer. 

1. It's a plain Java library
2. Not a Maven plugin

Well, this is what I tried inside my library.

File reportFolder = new File("target/myLibrary"); 
reportFolder.mkdir(); //this creates folder in the project which is using
the library, so far so good
and then
File foldersToBeCopiedFromMyLibrary = new
File("src/main/resources/bootstrap"); //this is inside myLibrary project
FileUtils.copyDirectoryToDirectory(foldersToBeCopiedFromMyLibrary,
reportFolder);

And this fails on FileNotFoundException because the project which is using
myLibrary doesn't have bootstrap folder in src/main/resources. So I can
actually create folder in the client project but I don't know how to copy
files and folders from library project to it's client which is using it.
(it's the same case like the Surefire does, it's copying CSS and JS files to
the target/surefire dir in the client)

P.S. I tried to look at Surefire sources before I have posted this question
but I couldn't find my answer there.



--
View this message in context: http://maven.40175.n5.nabble.com/How-to-create-new-directory-in-target-folder-with-Maven-tp5769636p5769681.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to create new directory in target folder with Maven

Posted by Robert Scholte <rf...@apache.org>.
"I am writing a library"

Just to be sure we're on the same page: are you writing Java code or Ant  
scripts?
And you're not talking about writing a Maven Plugin, right?

In that case it's a plain Java question: File.mkdirs() [1] does the magic
Since you're referring to an open source project, you could also have a  
look at its sources. Not sure if the surefire-plugin is the best example,  
because it does much much more.

Robert

[1] http://docs.oracle.com/javase/6/docs/api/java/io/File.html#mkdirs()


Op Fri, 06 Sep 2013 22:06:05 +0200 schreef Bidlo <pe...@gmail.com>:

> I am writing a library which will create a report based on the test  
> results
> (imagine something like 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.
>
> 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.
>
> 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>
>
> I also tried to execute this code inside my library
> FileUtils.copyDirectoryToDirectory(new  
> File("src/main/resources/bootstrap"),
> new File("target/myLibrary") but I will get obvious  
> FileNotFoundException -
> bootstrap doesn't exist in the project which is using the library
>
>
>
> --
> View this message in context:  
> http://maven.40175.n5.nabble.com/How-to-create-new-directory-in-target-folder-with-Maven-tp5769636.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org