views:

438

answers:

7

I use Eclipse for Java development.

There is an *.exe file in a subdirectory of my workspace, which keeps getting deleted.

Specifically, one of the projects is dedicated to C++ development using MSVC; there is no Java there. The root of this project has cpp and h files, and I use MSVC to generate the exe under the /bin directory.

As part of its built-in build process, Eclipse deletes this exe file as it compiles *.java files, apparently because it thinks that the exe file is binary output. Note that the exe is not in any /target directory.

By the way, I am using the Maven-Eclipse plugin, but this behavior apparently occurs when Eclipse is building the workspace, not part of a Maven run.

I'd rather keep the exe in this directory; it is the right place to have it, and so I would rather not go to the effort of moving it as a workaround. How can I prevent this from happening? Is there some configuration within Eclipse where I can state that exe files are not to be cleaned when building?

+3  A: 

You could try setting the .exe as 'read only' for a quick fix.

Gordon
sneaky but effective :)
orip
A: 

I'm assuming this sub-directory is Eclipse's 'target' directory in order to have the EXE file in the Java programs current directory.

You could then (for example) launch your program in Eclipse with a -Dsettingname=%path% that your program reads (from System.getProperty("settingname") ) to inform it about the location of this exe.

If the setting is omitted the program can continue to assume the current directory, enabling you to bundle it when creating a distributable.

Kris
> output folder of the build pathThanks, but it is not an output or target folder. Please see my comment to the response above by Thorbjørn Ravn Andersen
Joshua Fox
+3  A: 

The only place this usually happens is in the output folder of the build path when Eclipse cleans it.

The easiest way is to create a new source folder and put the exe file in a package corresponding to where you want it to end in the output folder. The build process then automatically copies as appropriate. This is the same way as you do it with properties and other files which need to end up in the class path.

Thorbjørn Ravn Andersen
> output folder of the build pathThanks, but it is not an output or target folder. Actually, in my workspace, this is a Eclipse-project with no Java, only C++. There are cpp and h files in the root of this project, and I compile them into an exe in the /bin subdirectory using MSVS. I'd like Eclipse to ignore this project completely in the build process. I use the Maven-Eclipse plugin, but the problem described is not occurring when I run Maven, but rather when Eclipse builds the workspace, e.g., if I select project-->Clean->All.
Joshua Fox
Your question is badly worded, then.
Thorbjørn Ravn Andersen
+3  A: 

I don't think that deleting exe files during a build/clean process is normal behavior. What kind of Eclipse project are you using?

Anyway, under "Properties", "Java Compiler", "Building" there are some options you can configure. If you require more flexibility, create a project from an Ant build file and define cleaning behavior there.

kgiannakakis
> What kind of Eclipse project are you using?The Maven/Eclipse plugin is configuring these Eclipse projects for me. However, the problematic phase appears to come during the Eclipse building process, not when I launch Maven.
Joshua Fox
I set Filtered resources (at the Eclipse dialog which you mentioned) to include *.exe. Is this what you mean?
Joshua Fox
No, this refers to the files not to be copied to the output folder. You could untick the 'Scrub output folder when cleaning projects' checkbox - since you aren't doing any Java you don't need it anyway. However, I don't know if this will work. It has to do with the project structure and probably Maven-Eclipse has something to do with it. A normal Java project doesn't delete exe files.
kgiannakakis
+1  A: 

Eclipse does not touch any files during a clean build outside a directory you told it. You can have all kind of files around, be it an exe or whatever, it will not touch! A clean is meant to clean all output folders. Conclusion: your exe is in fact (directly or indirectly) in such an output folder (maybe you just don't notice) or it is not eclipse that deletes the file (even if it seems so).

To make sure eclipse does not touch anything in your proect check the file ".project". In this XML file there is a node "buildSpec" where all eclipse builders that touch your project are listed. Save the file somewhere else and then remove all entries unter "buildSpec".

In my example the original ".project":

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>org.jmock</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
     <buildCommand>
      <name>org.eclipse.jdt.core.javabuilder</name>
      <arguments>
      </arguments>
     </buildCommand>
     <buildCommand>
      <name>org.eclipse.pde.ManifestBuilder</name>
      <arguments>
      </arguments>
     </buildCommand>
     <buildCommand>
      <name>org.eclipse.pde.SchemaBuilder</name>
      <arguments>
      </arguments>
     </buildCommand>
    </buildSpec>
    <natures>
     <nature>org.eclipse.pde.PluginNature</nature>
     <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

After edit:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>org.jmock</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    </buildSpec>
    <natures>
     <nature>org.eclipse.pde.PluginNature</nature>
     <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

After this edit make sure the exe is present. Then clean your workspace. Your exe will not be deleted (at least not by eclipse).

If this does not help you ... maybe you have installed an ... fancy ... plugin that somehow deletes the exe? Something that does not ship with eclipse?

Arne
+2  A: 

The problem is you are storing your executable in /bin, which is an Eclipse output directory. This directory gets removed each time you do a clean build. Solution: store your executable elsewhere (i.e. /exe).

Adriaan Koster
This makes a lot of sense! I will try this.
Joshua Fox
Or alternatively, set Project->Properties->Java Build Path->Default output folder to some nonsense name (since this "project" does not actually have any Java.
Joshua Fox
Also, one can set Project->Java Compiler->Building->Enable Project Specific Settings->Filtered Resources *.* and also deselect "scrub output folders."
Joshua Fox
+1  A: 

A quick and simple fix for your problem might be to just copy the *.exe file into (one of) your src/ folder(s) too or to add a new folder with only this file in it as source to the project just for this porpose. Eclipse will then always copy the *.exe back into bin/ when it rebeuilds your project.

Actually by default Eclipse seems to copy everything it finds in the source tree (and of which it doesn't know how to compile) into a respectively named subdirectory of the output directory.

x4u