0

thanks in advance for the help!

To clarify my problem:

1) I have an ec2-instance and wrote a java program. I've called it HelloWorld.java

2) I've built a jar file for HelloWorld.java called hello.jar using maven. I used a random pom file with some random dependencies since I figured HelloWorld doesn't need a pom file other than to give the jar file a name.

3) I've been using a spark-submit script to submit apps, but the app I am now trying to run does not have spark involved in it and I want to also deploy it in an environment where spark is not involved. So I want to submit the app using the "java" command. I am not sure if I should be submitting the jar file, the .java file, etc. I've seen that I have to give it a .class argument. I'm not sure what to put?

4) My next step is having a java program that has a set of 4 jars dependencies. I would love to know how I can add the 4 jar files as an argument for the "java" command.

EDIT @Ascalonian

I tried John Skeets answer and got this exception when I tried the jar command:

java.io.IOException: invalid header field
        at java.util.jar.Attributes.read(Attributes.java:393)
        at java.util.jar.Manifest.read(Manifest.java:182)
        at java.util.jar.Manifest.<init>(Manifest.java:52)
        at sun.tools.jar.Main.run(Main.java:151)
        at sun.tools.jar.Main.main(Main.java:1149)

EDIT 2 John Skeet's answer ended up working when I recreated the solution. No idea what changed, but it worked. Thanks for the help!

Thanks!

Thank you!

1 Answers1

3

You need to make your jar an executable one and add manifest to it:

Something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>theMainClass</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

Refer: How can I create an executable JAR with dependencies using Maven?

Community
  • 1
  • 1
Abhi
  • 98
  • 9