Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to create package-info.java for existing packages in one move in eclipse?

I have some legacy packages which doesn't have package-info.java. For some reason I need to create package-info.javas for them and I found the task really boring because there is no shortcut in eclipse for me to do that. I have to manually use the New > File procedure to create the file, then manually type in those package names.

Is there a shortcut in eclipse for such task?

like image 590
glee8e Avatar asked Jul 04 '16 04:07

glee8e


People also ask

How do I move a package to another package in eclipse?

Right-click the package you want to move, and select " Refactor/Rename..." -- NOT " Move "! Modify the name of the package to reflect its desired new position in the package hierarchy, e.g. Prepend any new parent package name(s) if you are moving the package to downwards in the package hierarchy.

What is package-info Java in JAXB?

package-info. java is a way to apply java annotations at the package level. In this case Jaxb is using package-level annotations to indicate the namespace, and to specify namespace qualification for attributes (source).


2 Answers

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.

like image 133
Leo Izen Avatar answered Sep 17 '22 17:09

Leo Izen


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.

like image 20
Tordanik Avatar answered Sep 17 '22 17:09

Tordanik