Current Netbeans Project File Path

Netbeans will be the right way to get the file path in the current Open project. In the module I'm developing, I need to get the path to Project for FileChooser, however most of what I tried just returned the path to the module from which it runs. Is their way to get the path to the project from which the method runs?

+5
source share
3 answers

Well, I figured it out a bit, although I definitely don't like the fix. Since the file is in the project directory, its execution and its DataObject is in the search for the DataNode used to create the tree structure, which I just used: (... (DataNode) getParentNode () getParentNode () getParentNode () getParentNode ()) getDataObject () getPrimaryFile () ..;

I do not really like this method, but now it works fine.

0
source

Try to get an instance of Project through a search, and then

        private String getProjectDirectory(final Project project) {
            try {
                FileObject projectDirectory = project.getProjectDirectory();
                return FileUtil.toFile(projectDirectory).getAbsolutePath();
            } catch (Exception e) {
                //ignore the exception
                return null;
            }
        }
+2
source

Right click on the project. Click properties. Sources Tab The path "Project folder" is at the top.

0
source

All Articles