running scala apps with java -jar

后端 未结 5 1977
日久生厌
日久生厌 2020-12-09 02:02

I got some problems with the java. Check it out.

sebastian@sebastian-desktop:~/scaaaaaaaaala$ java -cp /home/sebastian/.m2/repository/org/scala-lang/scala-libr

相关标签:
5条回答
  • 2020-12-09 02:16

    use sbt-assembly sbt plugin to produce a jar containing all dependencies

    sbt-assembly github

    e.g. add a line in project/plugins.sbt:

    addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

    adjust your build.sbt e.g. with

    mainClass in (assembly) := Some("mypackage.mysubpackage.MyMainClass")
    assemblyJarName in assembly := "my_assembly.jar"
    

    then build your assembled jar with

    sbt assembly

    and launch it with

    java -jar ./target/scala-2.12/my_assembly.jar

    Et voilà, no class-path this & thats needed any more. only 1 jar.

    0 讨论(0)
  • 2020-12-09 02:22

    Simply running

    scala scaaaaaaaaala-1.0.jar 
    

    works for me with 2.11.6

    0 讨论(0)
  • 2020-12-09 02:26

    If you define -jar the -classpath is ignored:

    Java manual:

    -jar When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

    You can define the classpath dependencies in the Manifest metadata.

    The easiest way to start your app is using the scala scripts:

    scala -classpath target/scaaaaaaaaala-1.0.jar scaaalaaa.App Hello World!
    
    0 讨论(0)
  • 2020-12-09 02:29

    For an executable jar, the classpath should be in the jar's manifest. For help on doing that, look through the answers to Stackoverflow: How to create an executable jar with dependancy jars.

    0 讨论(0)
  • 2020-12-09 02:29

    Below is the way to execute the Scala Executable Jar

    • We need scala installed in your system.

    • Here first will give the jar path and jar name

    • If your code needs any dependency jar then keep all jar in one directory and give a path of this in command like below after the ":".

    • At last give your class/object name.

    scala -cp "/your/jar/path/jar_name.jar:/your/dependency/jar/path/*" SampleCode

    0 讨论(0)
提交回复
热议问题