1

I'd like to export my eclipse project as a JAR from the command line, but have only done this through the Eclipse UI with File -> Export -> Java -> JAR.

190290000 Ruble Man
  • 2,173
  • 1
  • 20
  • 25
  • Eclipse doesn't necessarily execute a shell command. – Stephen C Oct 25 '15 at 02:58
  • Surely there must be some equivalent shell command for Eclipse's build/run/export, or am I that hopelessly naive? – 190290000 Ruble Man Oct 25 '15 at 03:00
  • There probably is. But it isn't necessarily so. Eclipse could be generating the JAR file itself, and it could be doing it in a way that is not 100% compatible with what you can generate with the Oracle `jar` command. – Stephen C Oct 25 '15 at 03:08
  • And if you are using Ant or Maven as the build tool (from within Eclipse), you also have to consider how >>they<< generate JAR files. – Stephen C Oct 25 '15 at 03:11
  • 3
    Anyway, the real answer if you want to generate a JAR file from the command line is to read the manual entry for the "jar" command, not to try to reverse engineer what Eclipse is doing. (This in an "XY problem" ... http://mywiki.wooledge.org/XyProblem) – Stephen C Oct 25 '15 at 03:13

1 Answers1

2

The Java JDK provides the jar command: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jar.html

For more elaborate uses, you may be well advised to consider something like Apache Ant or Maven:

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • Right. The jar command is key, but I have some libraries in my buildpath and I want to make sure that all the dependencies are packaged the exact same way as what Eclipse does. – 190290000 Ruble Man Oct 25 '15 at 02:56
  • @190290000RubleMan Is your Eclipse project configured as a Maven project? – ziesemer Oct 25 '15 at 03:01
  • It's not. Just Java :) This question is making me start to think that Eclipse may not use a shell command for build/export http://stackoverflow.com/questions/863181/is-it-possible-to-view-what-shell-commands-eclipse-is-making Nonetheless, there must an equivalent command that I can use for build/export. There must! – 190290000 Ruble Man Oct 25 '15 at 03:03
  • This question might seem useful as well. http://stackoverflow.com/questions/206473/build-eclipse-java-project-from-command-line – 190290000 Ruble Man Oct 25 '15 at 03:05
  • @190290000RubleMan 0 Correct, it doesn't use a shell command. Per the link you provided, you could consider letting Eclipse generate an Ant script for you that you could use. However, for best portability and a full feature set, I'd recommend using m2e to let Eclipse help you manage your Eclipse as a Maven project. Then Maven's `pom.xml` owns your project configuration instead of Eclipse-specific `.project` and `.classpath` files - and then you can run any number of various build options from either the Maven command-line (using `mvn`), or from within Eclipse using m2e. – ziesemer Oct 25 '15 at 03:05
  • so what do I need to get started with m2e? I have it installed. – 190290000 Ruble Man Oct 25 '15 at 03:07
  • 1
    @190290000RubleMan You may like to start with https://books.sonatype.com/m2eclipse-book/reference/ . – ziesemer Oct 25 '15 at 03:14