tags:

views:

38

answers:

1

Hello, in my Java Eclipse project that contains JUnit tests, I also have a package "resource" that contains all input data used for the tests. But when compiling JUnit tests, the Java compile also data available in resources, so I find the same data in the "bin" folder. Is there a way to avoid this?

thanks.

A: 

If you have a particular package within the source path you want to exclude (your resources folder for example), you can right click on the package and select: Build Path > Exclude.

This will tell Eclipse that you don't want to include that package as part of the build.

This is making a couple of assumptions: that you're using Eclipse Helios (because the option might be different in older versions), and that the resources are stored in the same folder as your regular java source files (because if resources is in a folder by itself, you can remove that entire folder from the build by using Build Path > Configure Build Path -> Source tab.

Update:

After the discussion in the comments regarding why you would or would not want to copy resources into the bin directory:

  • The contents of your bin directory should be ignored and not checked into to a version control system (when using CVS, bin should be an entry in the .cvsignore file)
  • The resources are only duplicated on your local machine, which is fast and hard discs are big. I'm not sure you should be worrying about this
  • If you're using Class.getResource to access those resources, they need to be on the classpath somewhere. The bin directory is as good a place as any

So, realistically (barring some unknown, like the files are hundreds of gigabytes or something), I don't think you need to be concerned about excluding these files from the build.

Ash
Ash, thanks for the correction of grammar. with helios, I tried to exclude the resource package(that contains data) and the package become a source folder ??? could I always access data by getResource?
laura
Sorry laura, I'm struggling to understand what you mean. Was your "resource" package part of a source folder to begin with? In my Eclipse, you can't "Exclude" something that is not already part of a source folder. If you're using `Class.getResource` to load resources, you probably want them included in your bin directory.
Ash
my package : com.software.test.data.inputs and in inputs package ,I have data files => so the inputs package is a resource
laura
So you want to stop the files in `inputs` being copied to `bin`? If so, right click on inputs and exclude it.
Ash
yes it's what I want, but just to be sure, If I do that I can always access to data via "getResource"?
laura
I don't think so. For `Class.getResource` to work, the resource needs to be on the classpath. By default that is your bin directory. Which leads back to the question: why do you want to remove your resources from the bin directory?
Ash
I want to remove the resource from bin, because it contains many data ,and I think it's too heavy to copy each time data to the bin and with CVS, we have to excute only ".class" and not data
laura
@laura: I've updated my answer to include CVS and other issues mentioned here in the comments
Ash
ok,Ash. If I haven't to worry about size of data and copying data to the bin and if it is fast, how could I ignore bin to not be managed with CVS ?
laura
See my answer. Or read: http://cvsbook.red-bean.com/cvsbook.html#cvsignore
Ash
Ash, I see your answer , but my question was how if it's inside eclipse, where do I can find cvsignore ? just I do not know if it is a function inside eclipse to configure to avoid managing bin in CVS or should I write some script to do it ? thanks
laura
It is a core function of CVS itself. I haven't used CVS for years, but I imagine the process from within Eclipse will be something like: Right click on `bin` and select `Team -> Add to .cvsignore`. This will create the `.cvsignore` file for you.
Ash