How to create packages (folders) in an Eclipse project through a plugin

I am trying to develop a small plugin for Eclipse to create multiple Java files in multiple folders (packages) as a starting point for a new module of larger software.

I tried using the object IFileas follows:

final IFile file = container.getFile(new Path(myFileName));
...
file.create(stream, true, monitor);

This works as long as all folders on the file path exist. But it does not create the missing folders (new packages), but it throws a "resource does not exist" exception.

I could not find a way to do this using objects IResourceor IWorkspace.

+5
source share
2 answers

, , - :

IFile file = project.getFile(newPath);

prepare((IFolder) file.getParent());

public void prepare(IFolder folder) {
    if (!folder.exists()) {
        prepare((IFolder) folder.getParent())
        folder.create(false, false, null);
    }
}

.

+9

, , Maven? , Eclipse .

0

All Articles