简体   繁体   中英

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)?

I don't have a mainClass but I wish to run it depending on the modules I want to execute.

Things I tried:

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.

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 -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 ).

Since it can be run as a normal java program, you can use the Exec Maven Plugin . I confirm that it is viable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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