Jump to content

Write scripts with VS Code


BrainDeadGenius

Recommended Posts

For those of you who don't use VS Code, I highly recommend swapping to it. When I first started writing scripts back in 2013 for OSB, I was using IntelliJ, I believe. However, VS Code offers so much more flexibility, and now that it can compile jars for you, I think it's a better option than Eclipse and IntelliJ. So, here's the guide on how to get you up and running on VS Code.

You will need to ensure that you have the Java JDK 1.8+ already installed. If not, download it from here -> https://www.oracle.com/java/technologies/javase-jre8-downloads.html

Next, you'll want to install Maven as this is what will be used to compile your script.

  • Go to http://maven.apache.org/download.cgi and download the archive.
  • Find a place you want to store the unzipped files. For me, it's on a secondary drive (Z:\Programs\maven)
  • Edit your environment variables
    • Here, you'll want to append the path to the bin folder of Maven to your global Windows path (for me: Z:\Programs\maven\bin)
    • 4e4000614f4bdef499aba8400d7fb55f.png
    • While you're here, you'll want to add a new user variable called JAVA_HOME if you don't already have it. This is required for an extension in VS Code in order to create the Java project. You'll see that mine is on the C drive.

If you haven't done so already, download VS Code: https://code.visualstudio.com/download

Then you'll need to add some extensions. You'll want to click the tab with the four boxes, shown below. And then you want to search for the Java Extension Pack. This will install the Maven extension as well as debugging and Java language support extensions which are helpful for writing Java.

888a024890f9837e7bc260b9d3f86e97.png

 

Once that is done, you can create your first project. On Windows, press CTRL + Shift + P and a dialog should pop up. With your new extensions, you should be able to type Maven and be able to select the option Maven: Create Maven Project.

29394f31fe5f164eeb4023371d03b0e7.png

You'll then be able to select different libraries and default templates for the project. Select maven-archetype-quickstart as this will provide a small bootstrapped Maven project. You'll then be asked for the version you want. Pick the latest version (at this time, v1.4). Then choose where you want the project's folder to be created.

8a5e6c212de681002def3789a06249e9.png

Next, you'll be prompted with questions for the setup of the project. Enter the values based on your project scope.

a02234b93ce676a4177774605cabd941.png

You'll need to add the OSB jar file to the project. There is a command you can use to do this, but it's currently broken and doesn't add the dependency to the classpath at this time. So, the quickest way is to paste the following code in .classpath while replacing the path to your OSB file. You will also need to create a folder called lib and add the OSB file there. If you have errors in building your project later on, then you can additionally press CTRL + Shift + P and choose Java: Add a jar file or a folder to project classpath and select the OSB jar file. This will create a .vscode folder with settings.json with reference to the the lib folder you created and the classpath information you added below.

<classpathentry kind="lib" path="Z:/Cloud/Development/OSBot/OSBot 2.5.67.jar" />

28f483258b401bca8815e7f93931b295.png

I'm going to skip over writing Java for OSB at this time. When you're ready to build your project, you can do it via command line, or through a command in VS Code. Either way, it'll use Maven which you installed earlier. On Windows, press CTRL + Shift + P and type in Maven. You'll want Maven: Execute Commands

beac76253bcf5071130eea6ecdf9838f.png

You'll need to select the project, which should default to the project you have open. Then you'll need to select package

d9f1866b36d7c183989f35aaccd7b7ff.png

966e3113a34b3aa1a909313e853bec33.png

Once that is done, you'll have a folder called target inside your root project folder. Inside the target folder, you will have your built jar file, which you can then add to your OSB script folder.

43bcb10f7c716bc8ebdc8050ef255ef9.png

Edited by BrainDeadGenius
  • Like 2
  • Boge 1
Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...