Execute code after project is loaded


I'm extremely new to plugin development and trying to figure out how I can have some code invoked after a project has loaded.  I believe I just need to have my code call StartupManager.runWhenProjectIsInitialized, but I'm not sure how to have my code triggered in the first place when my plugin gets loaded.  I tried doing something like this in my plugin.xml:
  <extensions defaultExtensionNs="com.intellij">
      <projectService serviceInterface="RunOnStartup" serviceImplementation="RunOnStartup"/>

and put my code into the constructor of RunOnStartup, but the code did not get executed.  Can someone please let me know what I'm doing wrong here?  Thank you!


Comment actions Permalink

Services are always loaded on demand; if you simply create a service and don't have any other code that calls the service, it will never get instantiated. The easiest way to have code executed after a project is loaded is to implement the StartupActivity interface and to register your implementation as the postStartupActivity extension. You can find many example usages of this interface in the IntelliJ IDEA Community Edition codebase.

Comment actions Permalink

Thanks, this is exactly what I was looking for! :)


Please sign in to leave a comment.