简体   繁体   English

带有 maven 的 Scala:使用类执行 -jar-with-dependencies

[英]Scala with maven: Execute a -jar-with-dependencies with a class

It might be a stupid question, but I can't get my wrap my head around it.这可能是一个愚蠢的问题,但我无法理解它。

How to execute a jar created with maven package that brings quite a few dependencies with it (the resulting jar is 100MB)?如何执行使用maven package创建的 jar 并带有很多依赖项(生成的 jar 为 100MB)?

I don't have a mainClass but I wish to run it depending on the modules I want to execute.我没有 mainClass 但我希望根据我要执行的模块运行它。

Things I tried:我尝试过的事情:

1. 1.

scala  my_app_2.0.1-jar-with-dependencies.jar App1


    java.lang.NullPointerException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at scala.reflect.internal.util.ScalaClassLoader.$anonfun$tryClass$1(ScalaClassLoader.scala:44)
        at scala.util.control.Exception$Catch.$anonfun$opt$1(Exception.scala:242)
        at scala.util.control.Exception$Catch.apply(Exception.scala:224)
        at scala.util.control.Exception$Catch.opt(Exception.scala:242)
        at scala.reflect.internal.util.ScalaClassLoader.tryClass(ScalaClassLoader.scala:44)

2. 2.

scala -classpath my_app_2.0.1-jar-with-dependencies.jar package.path.App1

java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
    at org.rogach.scallop.ScallopConf.performOptionNameGuessing(ScallopConf.scala:17)
    at org.rogach.scallop.ScallopConfBase.verifyConf(ScallopConfBase.scala:686)
    at org.rogach.scallop.ScallopConfBase.verify(ScallopConfBase.scala:698)
    at iit.cnr.it.socialpipeline.utils.ArgConf.<init>(ArgConf.scala:19)
...

ANSWERING TO MYSELF, for future reference.回答我自己,以供将来参考。

Well since you created the jar with maven that works with java and since you used scala-plugin , and this is inside the dependencies you just need to use the command:好吧,因为您使用可与 java 一起使用的maven创建了 jar 并且您使用了scala-plugin ,并且这是在依赖项中,您只需要使用命令:

java -classpath my_app_2.0.1-jar-with-dependencies.jar package.path.App1

easy as that, you noob - no offense (well, I am answering to myself. So I think it's pretty fair to be rude to myself :D ).就这么简单,你这个菜鸟 - 没有冒犯(好吧,我是在回答自己。所以我认为对自己粗鲁是很公平的:D)。

Since it can be run as a normal java program, you can use the Exec Maven Plugin .由于它可以作为普通的 java 程序运行,因此您可以使用Exec Maven Plugin I confirm that it is viable我确认它是可行的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM