如何将一个简单的单个Scala文件打包为一个独立的jar(没有sbt)? [英] How can I package a simple single Scala file as a stand-alone jar (no sbt)?

查看:347
本文介绍了如何将一个简单的单个Scala文件打包为一个独立的jar(没有sbt)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Scala文件,我需要发送给某人在没有Scala(只有Java)的机器上执行。它只是一个文件,一个依赖于一个jar(除了scala本身)。

I have a very simple Scala file which I need to send to someone to execute on a machine without Scala (only Java). It's just one file, with one dependency on a jar (other than scala itself).

我正在努力正确打包它。我没有使用sbt或任何东西。什么是最简单的打包方式?

I'm struggling to package it properly. I'm not using sbt or anything. What's the simplest way to package it up?

推荐答案

假设你有一个文件Test.scala

Assuming you have a file Test.scala

object Test {
  def main(args: Array[String]){
    println("Hello world!")     
  }
}

用scalac编译它

scalac Test.scala

创建文件清单。 txt包含以下内容:

Create file Manifest.txt with the following content:

Manifest-Version: 1.0
Created-By: 1.6.0_31 (Sun Microsystems Inc.)
Main-Class: Test

将scala库从您的发行版复制到当前文件夹中并解压缩它:

Copy scala library from your distribution into the current folder and unzip it:

unzip scala-library.jar

执行命令:

jar cvfm Hello.jar Manifest.txt *.class library.properties scala/

发送给收件人。他/她将不得不执行

Send it to your addressee. He/she will have to execute

java -cp Hello.jar

这篇关于如何将一个简单的单个Scala文件打包为一个独立的jar(没有sbt)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆