JISA VS Code - OE-FET/JISA GitHub Wiki

Writing a JISA program in VS Code

A popular choice of code editor is VS Code. Java in VS code is very well supported, and it is something of a good choice for creating JISA-based programs.

Installing Java Support

To get started, make sure you have Java support installed by installing the "Extension Pack for Java". You can do that either by searching for it in the extensions manager or by pasting the following into the "quick open" box (opened by pressing Ctrl + P):

ext install vscjava.vscode-java-pack

Creating a Java Project

The easiest way to create a new Java project in VS Code, is to open a new folder, and simply create a .java file in it. For instance, we can create a Main.java file. Inside the file, we can add the usual scaffolding for a Java program:

public class Main {

    public static void main(String[] args) throws Exception {
        System.out.println("Hello World!");
    }

}

We should be able to run this program by clicking the "Run" link above our main method, or by clicking the run button at the top right:

If you haven't done this before, or don't have Java installed, you may be prompted to "choose" a JDK. Make sure to choose something that is version 11 or newer. VS Code will then likely download everything you need automatically.

Including JISA

Place a copy of JISA.jar inside the same folder as your .java file:

then expand the "Java Projects" section near the bottom-left of the window and drag the JISA.jar file into Referenced Libraries:

After a bit of thinking, the JISA library should be added to the classpath of your project, allowing you to import and use JISA classes. You can test this by invoking the GUI class like so:

import jisa.gui.GUI;

public class Main {

    public static void main(String[] args) throws Exception {
        GUI.infoAlert("Hello World!");
    }

}

Now, when running the program, we should get a pop-up window saying "Hello World!" instead of the previous command-line output:

You're ready to go!

That's it, you're ready to write a program. When you're ready, and want to compile your java code into an executable JAR file, then you can do so easily by using the "Export JAR" button in the "Java Projects" section:

It will then ask which class to use as the main class (in our case that's the Main class, and the only option), and what to include in the JAR. In most cases you should just be able to hit enter to select whatever the default options are in both cases.