How to load an existing IntelliJ Java project into an com.intellij.openapi.project.Project object using some APIs instead of using from IDE process?

Answered

I have an existing IntelliJ Java project on my disk. I try to find a way to load this project into an com.intellij.openapi.project.Project object using some APIs so I can use project object to proceed some work.

I tried the following code:

ProjectManager projectManager = ProjectManager.getInstance();
ProjectManagerEx pm = ProjectManagerEx.getInstanceEx();
Project project = pm.loadProject("some project path...");

It throws exception in ProjectManager.getInstance(); where inside this method throws null pointer exception since there is no application object.

So is this the correct way to do that or is there any other way to get the project object?

Also, I find this blog post https://blog.jetbrains.com/platform/2020/10/new-implementation-of-project-model-interfaces-in-2020-3/ , will "WorkspaceEntityStorage" help to do that? If so, can you please let me know how to do that?

Thanks.

4 comments
Comment actions Permalink

Use com.intellij.openapi.application.ApplicationStarter extension point to run a custom command-line application using IJ platform.

0
Comment actions Permalink

Thanks for your reply, Yann.

My questions is that I am trying to write a standalone program to recognize IJ project and use some APIs provided by IJ to create a project object in terms of the project root path as an input. The IJ platform is not required to be installed in the system in this use case.

It seems "WorkspaceEntityStorage" could be an approach to this use case. Any thoughts on this? Thank you.

0
Comment actions Permalink

WorkspaceEntityStorage is only relevant for the internal data structures to model the project. It cannot be used standalone, like virtually all parts of IntelliJ Platform.

0
Comment actions Permalink

Thanks for the explanation, I appreciate it.

0

Please sign in to leave a comment.