...
Notice, the library dependencies have already been resolved thanks to maven:
Clicking on the plus icon and selecting a Java library allows us to choose the location for the jar file:
Once added, we can click 'Apply' to save our changes.
Ensure that habanero-java-lib has been added as a dependency to the module:
After confirming, click "OK" to save your changes.
We are now ready to write our first HJ application using HJlib.
To create a java file, right click on the 'src' folder and select New -> Java Class.
Use 'HelloWorld' as the name of the class and type in the sample program:
Here is the source code:
...
You will need to note the path of the HJlib jar file as we will need it to be able to run the HelloWorld.java
program from IntelliJ.
On my machine it is at /Users/shamsimam/.m2/repository/edu/rice/hjlib-cooperative/0.1.4-SNAPSHOT/hjlib-cooperative-0.1.4-SNAPSHOT.jar
Open the HelloWorld.java file in the editor and attempt to run it by right clicking on it and choosing the Run option:
Since we are running HelloWorld.java
without configuring the javaagent option, it is likely to intermittently fail with an error as follows: java.lang.Error: Calling function not instrumented
Or the
});
}
}
Now we can run this program by right clicking on the HelloWorld item on the project explorer and clicking run.
Running it for the first time will produce the following error:
Error occurred during initialization of VM
agent library failed to init: instrument
To fix this error, we need to correct set up the javagent JVM option before attempting to run HelloWorld.java
.
Java agents provide services that allow Java programming language agents to instrument programs running on the JVM. To run HJlib programs under the cooperative runtime we need to configure the JVM to use agents available in the HJlib jar. An agent is started by adding this option to the command-line:
...
We need to configure this in IntelliJ to be able to successfully run HJlib programs. Below is an image of what the configuration looks like after editing the run configuration:
Now we can run the program by clicking on the green play button.
Running the file on my machine produces the following output for example: