0

I have a Java program in Eclipse on Mac currently, and I normally have to use multiple clicks just to export my code into a .jar file to test on my server. I would like to automate the process via terminal.

Basically, I compile my code usually by selecting the project

  1. Export as Runnable JAR file
  2. Select library handling: extract required libarires into generated JAR
  3. Select export destination and hit done.

How can I do this via terminal? I assume this would first require me to compile the Java file, then to convert it to jar is a whole another step.

Help would be much appreciated.

3 Answers 3

2

You can create shell script that does it. This technique is obsolete since ~1998. So, use one of popular build tools. If you are starting now take a look on Gradle. Although there are a lot of other tools: good old ant, maven, buildr, ivy etc.

Sign up to request clarification or add additional context in comments.

Comments

1

You can script all these activities using a build script. Several libraries exist for this, but Apache Ant is a good place to start. Ant build scripts can be run from command line or within eclipse, and will do all compilation, packaging and (some) deployment for you with a single command.

http://ant.apache.org/

Comments

1
  1. Create default entry point manifest file as in : http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
  2. Open Terminal and create an executable jar file like this:

Sample Script:

#!/bin/bash

# set CLASSPATH if needed
cd workspace/src
javac -d . *.java
jar tf exported.jar .

11 Comments

Doesn't it need a Manifest?
What if i have .jar files that i rely on outside of the project folder?
@Djon: Thanks, added that step as well.
@user1436508 You can set the Class-Path attribute in the Manifest.
@user1436508: That's why I added that comment: # set CLASSPATH if needed
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.