Give the required permissions to the command prompt, such as making changes to the system. Go to the search box at the bottom of your home screen and search for ‘cmd’ or ‘command prompt’.Right-click on the command prompt and select “Run as administrator”. Method 2: Opening jar File Using Command Prompt Once this is done, you can directly click and run the JAR file. In it, click on ‘apply’ and then on ‘Ok’. When you click on the javaw, a box will appear. In the window that appears, go to C, then select “Program Files (x86)”. Scroll down to the bottom and click on “look for another app on this PC”. Click on ‘change’ in the box that appears. When you run this file, the jar file will open up along. Make sure you save it in the same folder where the JAR file resides.
In summary, if you wanted to see how to execute the main method in a Scala jar file with the java command, where the Scala jar file depends on external dependencies, I hope this example is helpful.In place of (filename), write the name of your respective JAR file.Ĭlick on ‘file’ then ‘save as’.Save the file with the extension ‘.bat’. I wrote about how to do that in Recipe 18.14 of the Scala Cookbook. Note that while this solution works for small projects like this, you’ll probably want to use the SBT-Assembly plugin for larger projects. For some reason I kept adding “.class” after it today, and of course it kept failing until I saw what I had done.) Summary (Note that you should not include “.class” after the $body part of that name. Knowing that the main method for a Scala object defined with “ extends App” will look like $delayedInit$body.Knowing that you need include the scala-library.jar file.Knowing how to use the java -cp approach.
I put that command in a shell script, and I use the \ characters to spread the full command across multiple lines to make it more readable. "htmlcleaner.jar:lift-json.jar:paranamer.jar:scala-library.jar:stockquotes.jar" \Ĭom.alvinalexander.GetStockQuotes$delayedInit$body \ Then the java command to run my application looks like this: Now, if you assume that (a) I have copied all of those jar files to the current directory (b) the application requires a configuration file be passed to the app on the command line (c) the package for the application is com.alvinalexander and (d) the first line of the application looks like this: The solution to my problem requires that I use the scala-library.jar file as another dependency, so I find it at /Users/al/bin/scala/lib/scala-library.jar, and copy it to my local folder. This jar file depends on these other jar files, which are in my project’s lib folder: Target/scala-2.11/stockquotes_2.11-1.0.jarįor the purposes of this article I’ll rename that file to: There’s a bunch of output from that command, but the final file it generates has this name: I run the following command from the root directory of my Scala project to do that: The first step in the solution is to package my Scala project with the SBT package command. (It looks like you can run Scala on an RPI, but for the moment I was curious how to get this working.)
I’m currently writing a little Scala code to download stock market quotes for my Radio Pi project, and I’m going to deploy the code to a “production” Raspberry Pi server that currently has Java installed on it, but not Scala. That being said, everything still seems nearly the same in late 2020. Note 2: This article was originally written in 2015, and used Scala 2.11.
Note 1: As I note in the Summary, you’ll probably want to use a tool like sbt-assembly for larger projects. To make things a little more complicated, my Scala project depends on three external jar files, and the main method requires a command-line argument. If you want to run/execute a main method from a jar file you created with Scala and the sbt package command, this tutorial shows how to do it.