How to create an executable . jar?

Asked

Viewed 1,258 times

0

Build a java project on eclipse, if yes, how?

Otherwise, as I compile a project in Java?


I was able to turn the code into . jar by eclipse. Only when I click to run it, it just doesn’t open.

I researched how to compile by cmd, using javac. I even managed compile, more create an executable . jar I could not.

Well, my question is, how to create an executable . jar from a project?

  • Here is a full explanation: http://luizricardo.org/2013/11/instalando-configurando-e-usando-o-eclipse-kepler/

  • What have you tried?

  • 2

    Higor, welcome to [en.so]! Eclipse is an IDE (Integrated Development Environment) and one of its objectives is precisely to automate the compilation of projects. I imagine you may be facing a particular problem, so I suggest you be more specific in your question so that we can help you better. Hug!

4 answers

1

But of course, one of its functions is this, if you already have the SDK installed and the project imported into the eclipse, just right-click on the project > Run As > Java Application.

0

Try exporting as Runnable JAR File: Export > Java >Runnable JAR File

0

Usually the IDE automates this for you, I use Netbeans and whenever you build the project it generates the jar, which is in the project’s dist folder. In the case of Eclipse I believe he also does it in some way (I don’t know). Now if you want to do it in CMD it is as follows:

1- Create a manifest.txt file in the package directory that contains your entire application with the following content (assuming that its main class is in the app.main package and has the name Mainwindow):

Main-Class: app.main.Mainwindow
Name: app/main/Mainwindow.class
Java-Bean: true

  • The first line 'Main-Class: ...' is where you define the package of your main class (class containing the main function), as if it were an 'app.main.Window' import'.
  • The second line 'Name: ...' informs which directory of its main class, from the directory of the manifest.txt file, if it is in the same directory as the main package, the first line will be similar to the second, the difference is that you use '/' instead of '.' and have to specify the extension '.class' of the main class.
  • The third line 'Java-Bean: true' tells you that you want to use the java bean option.

2-Open the CMD and navigate to the manifest.txt file directory, then type:

jar cfm Applicationname.jar manifest.txt app

So you specify the name of your application, include the manifest file that makes some important specifications about your file (.jar), and define what will be contained in (.jar), in this case the main package that contains everything is the app package. Is ready your jar!

0

Go on: > Files > Export > Runnable Jar File. Write the place where you want it to appear and choose the file Main, then click on Export.

If you don’t know what the file is main, is what has the function:

public static void main(String args[]) { }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.