Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying data files upon build in Java/Eclipse

Tags:

java

eclipse

Along with my java source, I have some data files that I would like to copy to the build dir when the source is build. Currently I am not using any build tools (e.g. maven or ant), but develop and run unit tests solely from within Eclipse. Can I somehow ask Eclipse to copy these data files when it builds my java code?

like image 675
someName Avatar asked Apr 09 '11 20:04

someName


2 Answers

First Create a new source folder call it something like res, you can use this folder to store your data files. Next open the Java Build Path section of the project properties (from the context menu of the project). Select the Source tab. In this tab you can control the output folders of each of the source folders. By default eclipse copies all the non-java files int the source folder to output directory during the build.

like image 59
Gorkem Ercan Avatar answered Sep 30 '22 11:09

Gorkem Ercan


Go with Ant. To be honest this is the best solution for automation of app building process.

I am not using Eclipse often. But I bet there must be a build file (build.xml) where you can add something like the code below to it and have it always executed when building your app.

This is how I am doing it in my build file for one of my projects. I am copying here two folders with all their content to a dist (which in NetBeans serves as a distribution folder where application jar is being created), so then I can easily run my application externally outside the IDE.

Be aware that the target name in Eclipse might differ. But you should find a correct one described in the build file probably.

 

<!-- to copy data & images folders' contents to dist folder on build. -->
    <target name="-post-jar" description="Copying Images">
        <property name="images.dir" value="${dist.dir}/images" />
        <property name="data.dir" value="${dist.dir}/data" />

        <copy todir="${images.dir}">
            <fileset dir="./images" />
        </copy>
        <echo level="info" message="Images folder content was copied."/>

        <copy todir="${data.dir}">
            <fileset dir="./data" />
        </copy>
        <echo level="info" message="Data folder content was copied."/>
    </target>

 

All the best, Boro.

like image 41
Boro Avatar answered Sep 30 '22 11:09

Boro