How to create a .jar executable?

0

Can you compile a java project in eclipse , if so, how?

Otherwise, how do I compile a project in Java ?

I was able to transform the code into .jar by eclipse. But when I click to run it, it just does not open.

I gave a lookup of how to compile by cmd using javac. I even got compile , but create a .jar executable I could not.

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

    
asked by anonymous 02.06.2015 / 22:06

4 answers

1

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

    
02.06.2015 / 22:11
0

Try to export as Runnable JAR File: Export > Java >Runnable JAR File

    
04.06.2015 / 06:03
0

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

If you do not know what the main file is, it has the function:

public static void main(String args[]) { }
    
08.08.2015 / 01:42
0

Generally the IDE automates this for you, I use NetBeans and every time you build the project it generates the jar, which is in the project's dist folder. In the case of Eclipse I think he also does it somehow (I do not know). Now if you want to do this 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 your main class is in the app.main package and is named MainWindow):

Main-Class: app.main.MainWindow Home  Name: app / main / MainWindow.class Home  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 you the directory of your 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 look like the second, The difference is that you use '/' instead of '.' and must specify the '.class' extension of the main class.
  • The third line 'Java-Bean: true' tells you that you want to use the java bean option.

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 defines what will be contained in (.jar), in this case the main package containing everything is the app package. Your jar is ready!

    
08.01.2019 / 21:35