How to create an executable jar file in eclipse

How to create an executable jar file in eclipse, running jar file and structure of jar file.

Right now your project is bunch of java files in Eclipse. But usually when you finish your application, you want to create a runnable file, so that somebody else can execute it. How to do that?

First you must test run your application in Eclipse. This will create a run configuration, which we'll use later.

I have here two applications. One is a console application and the other is a gui application.

To create a runnable file, you must right click your project and choose export. Choose Runnable Jar file and click next. There you must choose your launch configuration, which is the same as run configuration created earlier.

Type export destination jar file.

And choose what to do with libraries, that your application use. I usually choose to copy libraries into a subfolder. Click finish.

Now we'll go to the output folder. Here you can run your application in two ways. If your application is a gui application, you can click on jar file and it will run. If it's a console application, you must open command line and type java minus jar and jar filename.

By the way, what is jar file anyway? It's an ordinary zip archive, where are packages with class files and META-INF directory with manifest mf file. In this file is mainly defined application classpath and a default main class to execute if you want to run this application.


comments powered by Disqus

rss

Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects:
github

Search