When you develop a java project in eclipse, of course, you want to make class import automatically when you type a class name, especially when you copy & paste huge java source code to your java file. This article will tell you how to import java class automatically in eclipse.
1. Auto Import Java Class In Single Java File.
- Input the class name in the java source file.
- Click Source —> Organize Imports menu item or Shift+Ctrl+O in Eclipse, then the java class will be imported in the java source file automatically.
2. Auto Import Java Class In All Java Project Files.
If you have a lot of java source file need auto import used java classes, you can config your java project to achieve it.
- Click eclipse Project —> Properties menu item.
- Then click Java Editor —> Save Actions menu item in the left panel. Check the related checkbox in the right panel. In this case, we should check the checkbox Organize imports. And then click Apply and Close button to save changes. Now when you click the save button to save a java source file, all the referenced java classes in this java file will be imported automatically.
Reference