![]() In the previous example, the jlink was not able to find the library for scala.quoted package. This can be manually suppressed by adding the ignore configurations for those which are not really needed for the runtime. While building, there is a chance that you might be getting some errors due to unresolved dependencies. JlinkIgnoreMissingDependency := JlinkIgnore.only( To enable it, we can add this line to build.sbt: enablePlugins(JlinkPlugin) ![]() That means, the target system doesn't need to jave JRE/Java installed. jlink is a java tool which can identify and embed a minimal jre to the application. We can also use jlink based packaging in sbt-native-packager. More such configuration options are available in the sbt-native-packager documentation. maintainer := "Yadukrishnan "Ĭompile / mainClass := Some("") We can add more configurations in the build.sbt to customise the package. Similarly, for debian packaging, there should be relevant dpkg tools already installed ![]() However, please not that there may be pre-requisites to generate these platform specific packages.įor example, to generate msi package for windows, the the system should have WIX toolkit installed. Similarly, we can create rpn package, mac package, graalvm native image etc. For example, to generate a debian package, we can run: debian:packageBin Instead of universal, we can also execute platform specific commands to generate the package. We can just execute this script to run our application. It will contain two scripts (windows and unix based scripts) under the directory bin. This will create a zip package under /target/universal which can then be copied to anywhere and unzipped. Now we can run the sbt command: sbt universal:packageBin Let's first add the plugin dependency to the plugins.sbt file: addSbtPlugin("" % "sbt-native-packager" % "1.9.7")Īfter importing the build, now we can add the relevant configurations in build.sbt: enablePlugins(JavaAppPackaging) SBT Native Packager allows us to create a wide variety of native packging formats like exe, zip, msi, docker, etc. Here comes the use of sbt-native-packager. Also, it is not possible to create any other packaging formats using sbt-assembly. Especially, we might need to provide a lot of rules to handle deduplication. But if there project is getting bigger, sbt-assembly might be a bit of difficult to manage. SBT Assembly is a good plugin to create a jar file. More details are given in the sbt-assembly github page. Similarly, a lot more configuration options are available. Now, the jar file will be named as assemblyApp.jar. We can set a name for the jar file using: assembly / assemblyJarName := "assemblyApp.jar" Sbt-assembly also provides advanced configuration options. Java -jar app-packaging-assembly-1.0.2.jarīy default sbt-assembly uses the project name and the version number to generate the jar file name. We can now execute the jar file from the directory as: For other scala versions, the path will change accordingly. Since I am using scala-3.1.0, this is created under the above folder structure. This will create the jar file under the path target/scala-3.1.0/app-packaging-assembly-1.0.2.jar from the projecrt root. To create the package, we need to run the sbt command: We are now ready to create a packaged jar with just a few configuraitons in build.sbt. Val osName = System.getProperty("os.name") Now, we can create our sample scala class: package def mainMethod() = In this particular example, I am using os-lib librarby as a dependency. This is just to show that the dependencies are also packaged within the jar and we can run the assembly jar without any additional configurations for classpath. assembly / assemblyJarName := "assemblyApp.jar" In the plugins.sbt, add the sbt-assembly dependency as: addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")Īfter the re-importing the sbt build, let's add the required configurations in build.sbt. Let's look at it with an example.įirst of all, we need to create a simple sbt project. Sbt-assembly is a very simple plugin that can be used to create jar files for your scala application. ![]() And an executable jar file is the most simplest packaging we can create to run on multiple platforms. SBT is the most commonly used build tool for scala applications. Probably an IDE like VS Code(with Metals) or IntelliJ IDEA or any other editor is installed.(For this specific example, I am using Scala 3.1.0) Scala version above 2.12 is installed.Assumptionįor this to work, I am assuming the below conditions are met: In this small article, let's look at different ways in which we can package our simple Scala application. Different Ways To Package A Simple Scala App 1. ![]()
0 Comments
Leave a Reply. |