AJS.toInit(...) not working

Hi,

I am trying to execute some javascript code when my Jira ‘helloworld’ plugin loads, but nothing happens.

js/jira-report-plugin.js

AJS.toInit(function () {
    window.alert(99);
    console.log('helo');
    alert("hi");
});

resources/atlassian-plugin.xml

...
  <web-resource key="jira-report-plugin-resources" name="jira-report-plugin Web Resources">
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <resource type="download" name="jira-report-plugin.css" location="/css/jira-report-plugin.css"/>
    <resource type="download" name="jira-report-plugin.js" location="/js/jira-report-plugin.js"/>
    <resource type="download" name="images/" location="/images"/>
    <!--<context>jira-report-plugin</context> -->
    <context>atl.general</context>
    <context>atl.admin</context>
  </web-resource>
...

Solved:

Had to restart Jira/plugin.
atlas-mvn.bat package does not re-parse the atlassian-plugin.xml file.

The following had to be added to the atlassian-plugin.xml file (which doesnt come out of the box):

    <context>atl.general</context>
    <context>atl.admin</context>

I am logged in as admin, not sure if that has anything to do with it.

You might want to switch to atlas-debug and configure QuickReload (https://developer.atlassian.com/docs/developer-tools/automatic-plugin-reinstallation-with-quickreload). This will allow you to make changes to your add-on without having to restart Jira.

Quickreload seems to be working fine.
For some reason, QuickReload doesnt detect changes in atlassian-plugin.xml.
Unless it is working as designed.

Did you rebuild the JAR file? The atlassian-plugin.xml is different from other resources as this is actually used to generate the spring context. So for changes to the atlassian-plugin.xml you will need to run a build, which will be picked up by QuickReload.

I see. That would be much better than restarting Jira (takes 8min everytime).
Rookie questions:
but what am I building?
what command do I run? options? which folder do I need to be in? etc…

A typical development flow would be to go to your workplace folder in the command-line and run atlas-debug. This is a shortcut for a maven command which will do some AMPS magic. It will compile your add-on, start Jira in debug mode and get you up and running with QuickReload.

Now you can open your IDE and make changes to your add-on. If you make changes to resources like templates, CSS or Javascript it will be automatically detected by QuickReload. However, if you make changes to your JAVA classes or the atlassian-plugin.xml you will need to compile. In most cases, this would be a simple mvn package (or, if you want to use the atlassian SDK, atlas-mvn package) command. Or you could use your IDE to run the build for you.

The mvn package command will generate the add-on JAR file in the target folder, from where it will be picked up by QuickReload.

Got it, thanks for the details!