Search code examples
javaandroideclipsebuild-process

Eclipse custom program to build chain -- adding a source file


screenshot from Eclipse

I'm developing a quite big software for Android in Java (using Eclipse and ADT).

To support my development, I made an own command-line tool that does the following:

  1. Loads and processes certain Java files (from the project of my developed software)
  2. Outputs new Java files to a certain folder (so the input files are retained too) into my project

What the command-line tool does isn't relevant, its output is merely standard Java code (i.e. it's a code generator).

I would like that this command-line tool is automatically called during the build process. In other words, I want that when I'm finished with the manual coding and start the build process (e.g. by clicking "Run..."), the following happens:

  1. The command-line tool is run
  2. The files generated by the command-line tool are included in the build too (i.e. they are compiled exactly as if they were added and coded manually in the Eclipse project).

I'm pretty sure I have to add this program as a "Program" via to the Builder list of the project (see the attached screenshot). My questions:

  1. What position to put it? Should it be the first?
  2. What else do I need to do in order to meet the above requirements? I'm afraid that if the command line tool just writes the .java files to a folder, Eclipse will not see the newly generated files (as they are not added to its project file).

Solution

  • You are on the right track, and it will work fine given these conditions:

    • Your builder must be at the top, so it can modify the source files before the Java builder is running.
    • Your Java files must be generated into one of the existing "src" pathes of the project. Java files are not registered in the project, so if you put someting into a source folder of the project, it will be compiled. Eclipse tools like xtext and xtend work the same way.
    • The refresh option of your builder must be activated. Otherwise the workspace would not know that you created files (as your program works with java.io.File operations, thereby bypassing the workspace API for resources).