Compiling Only One Class in a Project

10,699

Solution 1

I think you can by going to the Project menu and selecting Build Working Set -> Select Working Set.

Select new, give your set a name then select only the single class you want to build. Once done it should build.

Next time you want to build, goto the Project menu and select Build Working Set -> and the name of the set you created.

Solution 2

I think Eclipse is smart enough to re-compile only those classes that you've actually changed in some way (even if other classes can't be compiled). So if you turn on automatic build, edit a class and save it, Eclipse will re-compile just that. I doubt that Eclipse re-compiles the whole code base if you—for example—rename one of your variables in a given class.

The bottom line is: stick with automatic building.

If you have some special use-case, then it would be good know what it is. Other than this James's answer could be your best shot.


I've created a little sample Maven project for myself in Eclipse (although it is a Maven project, Eclipse's automatic build works normally, like in a Java project, no magic there).

.
|-- pom.xml
|-- src
|   `-- main
|       `-- java
|           |-- A.java
|           `-- B.java // B contains erroneous "stuff"
`-- target
    `-- classes
        |-- A.class // A compiles without a word
        `-- B.class // even though it contains errors 
                    // B compiles too ... weird

(Note that in the package/project explorer window, under the target folder nothing is listed. I maybe imagining things, but normally classes, and other stuff are listed there ... not sure.)

Share:
10,699
IAdapter
Author by

IAdapter

Updated on June 20, 2022

Comments

  • IAdapter
    IAdapter almost 2 years

    I have build automatically turned off and I want to build only one class (for debugging). Is this possible? Other classes are already compiled in the build directory, but they might not compile under Eclipse.