Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: add import to a bunch of classes

I have 60 or so Java classes in an Eclipse project that I am reorganizing (everything was in the default package, ick!) that need to import another package in the project (newly created by other refactoring).

I would rather not do a Ctrl+Shift+O on every file. Is there someway I can speed this up?

like image 887
Alec Gorge Avatar asked Feb 27 '11 17:02

Alec Gorge


People also ask

How do I add all imports in Eclipse?

Press: CTRL + SHIFT + O and you should see below dialog boxes. Choose your desired import package and click next. It will prompt you for your next import and thats it. You are done.

Can you import multiple classes in a Java file?

import java. util. * will import all classes, but only the ones you actually use will be in the compiled code. It does not affect your program once it is compiled.

How do I organize imports in Eclipse?

Automatically organise import statements whenever you save Here are the steps to organising imports whenever you save: Go to Window > Preferences > Java > Editor > Save Actions. Select Perform the selected actions on save (off by default). Ensure that Organize imports is selected (on by default).

How do I select multiple classes in Eclipse?

How do people cut-and-paste multiple classes within Eclipse? I usually use ctrl + click to multiple select, then crtl + drag/drop to copy the classes to a new project.


Video Answer


3 Answers

Select the project in the package tree, and hit Ctrl-Shift-O. It will organize the imports for all the files of the project.

like image 90
JB Nizet Avatar answered Oct 01 '22 21:10

JB Nizet


Just click on your project and press Ctrl-Shift-O.

Or rightclick your project -> select "Source" -> Organize Imports

like image 24
Boris Avatar answered Oct 01 '22 21:10

Boris


Righclick on the source folder -> Source -> Organize Imports.

like image 36
Tom Seidel Avatar answered Oct 01 '22 19:10

Tom Seidel