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!

3
  • 1
    Do you have a Manifest in your jar?
    – Ascalonian
    Jan 15, 2015 at 19:40
  • 1
    For more help, you can look at John Skeet's answer to How to run a JAR file
    – Ascalonian
    Jan 15, 2015 at 19:42
  • @Ascalonian I do not have a manifest in my jar. Unless maven adds it for me? How would I go about adding a Manifest in my jar? Jan 15, 2015 at 19:44

1 Answer 1

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?

3
  • Do I add this in the pom file? Thanks! Jan 16, 2015 at 0:27
  • I tried adding this code plus a <plugins> </plugins> before/after in the pom file and it did not work as plugins was not recognized. How do I add the above to a jar file? Jan 16, 2015 at 0:32
  • you need to put plugins inside the build process: <build><plugins><plugin>...</build>
    – Abhi
    Jan 16, 2015 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.