Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: Is there a way to quickly export JARs

Tags:

java

eclipse

jar

So this may seem a bit vague, how quick is "quick" etc.

Well I'm just wondering if there is a way of exporting a JAR file in a quicker way than:

File -> Export -> JAR File etc etc.

Like can I Ctrl + Drag to explorer and it export with the project title and .jar?

like image 822
RedJax Avatar asked Jul 16 '13 22:07

RedJax


People also ask

What are the export options in Eclipse?

Export SubmenuAnt Buildfiles - Generates Ant buildfiles based on the configuration of the Java projects. Archive File - Exports files from the Workbench to an archive file in the local file system. Breakpoints - Exports breakpoints from the workbench to a breakpoint file.

How do I export a jar file with resources?

In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field. Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source files and resources.

How do I export a fat jar?

Start the Export Wizard from the File-Menu ("File" -> "Export"). Select "+ Fat Jar Exporter" and click "next >". Select the project "demorun" and click "next >". A Configuration-Dialog appears showing the current Settings.

How do I export a jar from an external library?

If it is a standalone (Main method) java project then Not any specific path put all the jars inside the project not any specific path then right click on the project - > export - > Runnable jar --> Select the lunch configuration and Library handeling then choose the radio button option "Package required libraries into ...


2 Answers

How to add custom shortcuts

To add or change shortcuts open: Windows->Preferences->General->Keys. Here you can find all the Eclipse commands and their associated shortcut keys.

Reference

You can add a custom binding in eclipse to export your jar using a keyboard shortcut.

Example

I added bindings both for Runnable and non-runnable jar:

  • Export Jar: CTRL+SHIFT+J
  • Export Runnable Jar: CTRL+SHIFT+R

enter image description here

How to do with Ant File

If you want the JAR to be generated automatically you can look at the following question:

  • Build project into a JAR automatically in Eclipse

How to do with Batch file run from Button

You can use the combination of the following two answers:

  • Create jar file from command line
  • In Eclipse, how can I add a toolbar button to run a batch file?

Basically create a batch file that makes the JAR... add a button that executes it.

like image 112
Menelaos Avatar answered Sep 28 '22 08:09

Menelaos


If using Maven a long term option would be to set up your build to 'package' your jar. Then just run the mvn package command from the command line or using the Eclipse Maven plugin. This method requires some upfront work, but it buys you a consistent and easy jar export.

like image 45
ABC123 Avatar answered Sep 28 '22 06:09

ABC123