4.10. Building Your Code

Problem

You want to create compiled .class files.

Solution

By default, compiled .class files are created or updated when you save your code. You also can perform builds manually.

Discussion

When you save a resource, .class files are built automatically by default. If that feature isn’t turned on, select Window Preferences Workbench, and then check the “Perform build automatically on resource modification” checkbox, as shown in Figure 4-15. To turn off automatic building, uncheck this checkbox.

Turning on auto-build

Figure 4-15. Turning on auto-build

To build a project manually, select Project Build Project.

Tip

If a .class file has been moved or damaged, auto-build won’t work, and you’ll have to start over by rebuilding the .class file yourself. In this case, select Project Build Project.

Changing the build order

Eclipse actually does a good job setting the build order of projects by interpreting project references itself. However, you also can set the build order yourself. Select Window Preferences Build Order, as shown in Figure 4-16.

Setting the build order

Figure 4-16. Setting the build order

Building only selected projects

If you highlight a project in a view and select Project Rebuild Project, the project you’ve selected is rebuilt. What’s cool about this is that you can choose only certain projects and just select Project Rebuild Project to rebuild them, without having to rebuild all projects (which Project Rebuild All does).

Get Eclipse Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.