Export Java as Jar application - java

i have a java project where i am accepting input from user and displaying output in console. I want to create a jar file so that other users can also run and use it. Can someone help me out with the steps. I am exporting jar file and running it but getting error " Could not find or load main class" while running.

If you use Netbean, it can build the jar file for you automatically. Just set your main class then click on clean and build.

Are you doing it through eclipse?
If yes, then follow below.
Make sure while exporting a jar to select an option under java as Runnable Jar file. Press next
Make sure you select Launch configuration, the one by which you run the project contains main method.
Hope it helps.

Related

exporting a java project to a server using eclipse

I have made a program that parses a text file and then works with the reuslt. I now need to compile this so I can deploy it on a server. 2 things.
1) I want to be able to update the text file regularly...is this possible without recompiling every time?
2) when I compile it with eclipse, I get a jar. If I click it nothing seems to happen. Any advice?
Thanks in advance!
Yes. You can do it without recompiling the program every time.
Create an executable jar from eclipse.
Select your project> File> Export > Java> Runable Jar File.
Please specify the main class where the main method exist.
Now it you click on this jar file , your program will be executed.
Note: If your program does not have any user interface, you will not see anything. When you will click on the jar program will be executed and immediate finished.

Run Java project (built in eclipse) using Batch File

I want to run my java project which i've built using Eclipse IDE. Now my goal is to create a batch file which will execute my project with one click. i referred question , but didn't get any idea. Please give me a solution. Thanks in advance.
Because you are working in eclipse, this makes things easier. First, export the whole program as a executable jar. You can do this by going to Files>Export and then in the pop up go to Java>Runnable Jar. Then follow the steps required to make it. Next you make a .bat file and write the following code.
start javaw -jar NameOfJar.jar
Make sure that you put the file in the same directory as your jar. Now you should be able and click on the .bat and execute the program!
1.Open Notepad & write
#echo off
javac YOUR_JAVA_FILENAME.java
java YOUR_JAVA_FILENAME
2.Save-As executeJavaProgram.bat
Make sure that YOUR_JAVA_FILENAME.java resides with your batch file and java path is set in environment variable.
3 . Double click on batch file.
Follow this tutorial to create a jar file of your eclipse project.
After doing it create a batch file in the same folder where you exported the jar with the command: java -jar yourjar.jar
Create jar file using eclipse i.e right click on your project select export jar file then provide file name to store your jar file. In this file eclipse will keep all .class file only and in META-INF folder main class definition if your are creating executable jar file.

creating and running jar file with source

I write a very simple java program with two classes: Business and Main.
I want to create a jar such that if I email it to someone they can:
run the program (i.e. run the jar)
open the jar to view the source code.
the code can run on mac or windows
I have been using IDEs for so long I have forgotten how to do this.
I am using netbeans 7.x
EDIT:
I found the following way on Netbeans:
properties > packaging > exclude from jar file :: delete **/*.java
But when I try to execute the jar using
java -jar mybusiness.jar
it says
no main manifest attribute, in mybusiness.jar
But note that my jar has a main class. Am I missing a manifest file?
You can export a JAR file that includes the source code using Netbeans:
Right click on the project and select properties
Build -> Packaging
Remove Java files from the excluded files. And select build jar after compiling
It will create the jar file that includes the source code if it successfully compiles.
Well surely an IDE can do this too?. Just make some text files and put the source into them and drag them into the ide's. It's java so it should automatically run on all platforms. I am not sure what the problem is here?
This link explains how do u create manifest file and how do you specify your main class in manifest file as its necessary for executing jar.

Macosx: How to make a runnable jar file in eclipse?

I will try to tell you exactly my problem, because I am stuck for more than 2 days now.
I am trying to make a project in Eclipse from existing source code (a program called sweethome3d) and then modify it. But, the problem even starts from even before modifying the code.
There are the steps that I am following:
File - import - existings projects into workspace.
I select the source code (http://sourceforge.net/projects/sweethome3d/files/SweetHome3D-source/SweetHome3D-3.3-src/SweetHome3D-3.3-src.zip/download)
Then, I try to export it into Runnable jar file
I have also to add some VM arguments in the command line when I try to execute it.
The runnable jar file does not run
in command line
with double click
Do you have any idea what I am doing wrong?
Thanks in advance.
If this is the same as the version of the code you're running, then SweetHome3DBootstrap.java, at line 90, is attempting to load com.eteks.sweethome3d.SweetHome3D dynamically. This class needs the class javax.jnlp.UnavailableServiceException, which is from javaws.jar.
So, when you try to run your JAR, it's missing javaws.jar at runtime. You'll need to either add it to the classpath (specified via the command-line when running, or via the JAR file's 'Class-Path:' manifest header), or re-package the classes from javaws.jar inside the JAR you're creating (like FatJar).
It could be some dependency problem, hard to tell without knowing more. Try using FatJar Eclipse plugin

How to convert the java project to .exe? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I convert my java program to an .exe file ?
Hello,
I coded a java project using Eclipse software. Now i need to convert that project to .exe file. I export that project and hence converted to jar file.
when i double click on it, it shows "failed to load Main-class attribute from 'path'". So unzipped it and looked into the MANIFEST. mf, there it has only version.
I also used JartoExe software and converted to exe file. It shows a cmd prompt like file but when i click it, i am just getting a flash of that window. Its not opening.
Please help me to convert the jar to exe file!!
Thanks in advance!
Take a look at this article: http://introcs.cs.princeton.edu/85application/jar/jar.html
You basically have to define what gets executed in the manifest and then if you want to your program under windows, you can either associate the jar type to java.exe or create a .bat file that starts the jar appropriately.
While exporting to jar file you need to provide the main class name, which is the entry point to your program.Once you do this, manifest file in jar will have entry for it and that will allow you to run it by double clicking on the jar.
When you choose Export from eclipse, one of the dialogs asks you what the main class is. If you specify it then when you double click on the jar it will launch the app.
Use JEXECreator 1.9.3, it is very good. It gives you two options to run your program: either using the console or the GUI
The easiest way to do so is to have a eclipse plugin "fat.jar" and add it to your eclipse
next you will get an option to build fat jar when you right click on your project.
Do restart of your eclipse after installing fat jar..
wow...
very easy...
http://www.ej-technologies.com/products/exe4j/overview.html
I once use this, it's good. But the free version has some kind of ads flash screen, if I'm not wrong.

Categories

Resources