Is there a way to create package-info.java for existing packages in one move in eclipse?
There is no easy way to do this as far as I know, at least "the right way."
What you can do as a shortcut is right-click package-info.java
and click "Copy." Then you can use the keyboard shortcut to paste the package-info.java
in any package. Eclipse automatically changes the package org.whatever.pkgname;
command to match the package you paste the java file into.
It's counter-intuitive, but Eclipse's "New Java Package" dialog with its option to create a package-info.java
works for existing packages, too.
Just right-click the existing package, select New > Package
, and leave everything except the "Create package-info.java" checkbox unchanged.
This will produce a package-info.java
that's pre-populated with the correct package name and an empty javadoc comment block (possibly with @author
tags and similar default content depending on your settings). Works even if you don't have an existing file to copy from. Tested with Eclipse Oxygen.
Just copy a package-info.java
file (via Ctrl+C and Ctrl+V) from one package to another package. Eclipse automatically corrects the package declaration in the copied package-info.java
file.