Clicky

How to make java code  install as exe on any computer. I want to make it work without go inside the code and compile it. I need to make it as other programs and put picture for the Ican and when you click on it automatically install it as other program.  

asked 12/09/2011 03:30

Abdullah15's gravatar image

Abdullah15 ♦♦


57 Answers:

If you want your users to be able to dobleclick on the icon and start java application - you don't need to package it as an exe file.

The way you do it - you cretae simple windows batch  file (.bat)
In this file you first set CLASSPATH pointing to location of your classes, jars

then  you eneter command

java ClassName

Then you place this file in some folder
and create shortcuirt say on the desktop to this .bat file
You can provide any incon to this shortcut.

After that - you just doubl-click on the shortcut and it will start your
application

 
link

answered

for_yan's gravatar image

for_yan

If you want to poackage it as .exe then you need to use some tool, launc4j or something like that
read this article about different options how to do it:
http://www.excelsior-usa.com/articles/java-to-exe.html

In many case though the simple .bat file as I described above will serve your purpose quite fine
link

answered 2011-12-09 at 23:37:12

for_yan's gravatar image

for_yan

In your way ,can put picture to the I con and install it on any computer or I have to have Java program  like NeatBeans on the computer.
Can you give me example what the code look like inside the Java file. I mean simple windows batch  file (.bat). I am try to learn how to do it for my purpose not for assignment. Thanks
link

answered 2011-12-09 at 23:39:58

Abdullah15's gravatar image

Abdullah15

You don't need to have NetBeans although as you used NetBeans designer, you can put approperiate jar on the claspath but probably
better if you packge your project into jarr on Netbeans
link

answered 2011-12-09 at 23:50:00

for_yan's gravatar image

for_yan

So you can do the following.

In Netbeans  make sure that your project runs fine as usual inNetbeans

Then  right-click on your project and select Clean and Build.
link

answered 2011-12-09 at 23:53:20

for_yan's gravatar image

for_yan

It will create .jar for you and it will write in teh resukts area something like this:

To run this application from the command line without Ant, try:
java -jar "C:\netbeans_projects\Converter\dist\Converter.jar"

(you may have another path of course)
link

answered 2011-12-09 at 23:58:24

for_yan's gravatar image

for_yan

I looked to my  project but didn't find jarr where I can find it? Other thing when you said Package you means I should take the name of the package which in the top of my code.  
link

answered 2011-12-09 at 23:59:48

Abdullah15's gravatar image

Abdullah15

the open dos cmd window and paste into that window this command which Netbenas will print for you

java -jar "C:\netbeans_projects\Converter\dist\Converter.jar"

Make sure that your Converter is running OK



link

answered 2011-12-10 at 00:01:28

for_yan's gravatar image

for_yan

Read my posting above -  starting with ID:37265687  -  I'm explaining to you how to do it
link

answered 2011-12-10 at 00:01:29

for_yan's gravatar image

for_yan

After you found that your converter is running fine in the dos window
got to any folder on your PC, say C:\Test\Converter

Copy file "C:\netbeans_projects\Converter\dist\Converter.jar" to that folder.

Create text file in this folder  and rename it into Converter.bat
Open it with the Notepad editor

Place the line

java -jar Converter.jar

in this file

Save the Converter.bat file



link

answered 2011-12-10 at 00:02:47

for_yan's gravatar image

for_yan

Open the folder C:\Test\Converter
in Windows Explorer

Right-click file Converter.bat and drag it to your Desktop
When you release the mouse - you'll see pop-up menu - select Create Shortcut

You'll get shortcut on your desktop
Double-Click the shortcut - your Converter should be running
link

answered 2011-12-10 at 00:09:47

for_yan's gravatar image

for_yan

C:\Users\Abdullah\Documents\NetBeansProjects\Converter1
I didn't see "dist"
I have
src, nbproject,build
link

answered 2011-12-10 at 00:12:04

Abdullah15's gravatar image

Abdullah15

Right-Click the shortcut on the desktop - go to Properties and change the icon id you want
link

answered 2011-12-10 at 00:12:34

for_yan's gravatar image

for_yan

Follow my posts consecutivelu staring from ID:37265687

Did you check that your app uis running in NetBeans ?

Did you then executeed "Clean and Build" - ? see my post ID:37265687
link

answered 2011-12-10 at 00:13:02

for_yan's gravatar image

for_yan

Yes I am trying , I copy it and past this "C:\netbeans_projects\Converter\dist\Converter.jar"  in dos RUN  and it showed me black window the  disappear immediately.
link

answered 2011-12-10 at 00:15:05

Abdullah15's gravatar image

Abdullah15

I don't have these option "select Clean and Build" when I click om my project
link

answered 2011-12-10 at 00:26:39

Abdullah15's gravatar image

Abdullah15

What menu you have when you right-click on the project name (on the project not on the java file, but on the whole project)

When you right-click on the project you'll see menu from the top :

New
Build
Clean and Build
Clean
....


what version of NetBeans you have ?

link

answered 2011-12-10 at 00:28:39

for_yan's gravatar image

for_yan

I got dis , I am looking for C:\Test\Converter , I went to C driver and I didn't see Test
link

answered 2011-12-10 at 00:34:41

Abdullah15's gravatar image

Abdullah15

Look, please raed what I'm writeing attentively.

>After you found that your converter is running fine in the dos window
>got to ANY folder on your PC, say C:\Test\Converter

go to ****ANY***** folder

c:\Test\Converter is a folder which I created as an example on my computer
to use it for placing the Converter.jar
You don't ned to have it - you can create this path or use different path to place jkjar in another place


It really does not matter how you call it.

So that it would be easier for you to follow my instructions, better create folder Test and then Converter ininside it so you have the same path as me.
Other than that you can name  the folder any way you like
link

answered 2011-12-10 at 00:38:56

for_yan's gravatar image

for_yan

I created   Converter.bat file inside converter then inside dis   , Am I right because I didn't see C:\Test\Converter
link

answered 2011-12-10 at 00:46:33

Abdullah15's gravatar image

Abdullah15

I am follow you step by step. try to reach what you want from me to do, just I need sometime
link

answered 2011-12-10 at 00:48:36

Abdullah15's gravatar image

Abdullah15


You can create it inside dis for now

Just understand taht in general you are not connecteced o NetBeans in any way - you cna copy
this jar to any arbitrary folder - test\Convereter was jsut aritrary nae which I selected - you just ned to have jar in that folder
link

answered 2011-12-10 at 00:49:55

for_yan's gravatar image

for_yan

I got all you said but when I click on it I saw Black window and fast disappear. Why? and the program doesn't run.  as you said I create New file on my  PC then I put the text file which I named  Converter.bat then I put inside it this line "java -jar Converter.jar"
and I drag it to my desktop. but it wont work  
link

answered 2011-12-10 at 00:51:37

Abdullah15's gravatar image

Abdullah15

Open dos windowe - go to the folder where you have yor jar and bat foile and typoe this command java -jar Converter.jar at the dos prompt - paste what youi see
link

answered 2011-12-10 at 01:10:19

for_yan's gravatar image

for_yan

Sorry man, I really work with you and I am learning. I learned from you a lot of thing. I worked with Java long time a go and I return back to it when I continue my education. I stoped dealing with Java almost 5 years and now I am return back to it. I really learned from you a lot but I like to ask about everything.
link

answered 2011-12-10 at 01:14:59

Abdullah15's gravatar image

Abdullah15

So waht about error you are seeing when you manually type

java -jar Converter.jar

in dos window?

Open dos windowe - go to the folder where you have yor jar and bat foile and typoe this command java -jar Converter.jar at the dos prompt - paste what youi see
link

answered 2011-12-10 at 01:17:31

for_yan's gravatar image

for_yan

What does this window mean. It stop for a little bit then  disappear.
link

answered 2011-12-10 at 01:29:08

Abdullah15's gravatar image

Abdullah15

Is there something wrong I did in side this file.
link

answered 2011-12-10 at 01:46:35

Abdullah15's gravatar image

Abdullah15

You go to that folder and without any file type your self on the command line

java -jar Converter.jar

Nothing should diappear after tthat
and paste the error message - the top of it - the first lines, not the last lines which are far less informative
link

answered 2011-12-10 at 01:55:04

for_yan's gravatar image

for_yan

>>How to make java code  install as exe on any computer.

Do you mean as an executable on any computer or as an .exe on Windows? Only Windows has exe files.

Java is cross platform so you can run it on any platform. It's not possible to produce an executable that will run on any platform.

You'd be much better off packaging your app as a Web Start app. You can do so in a way that will run on any platform, plus install the Java runtime if it's absent (which of course it might be)
link

answered 2011-12-10 at 02:32:01

CEHJ's gravatar image

CEHJ

I works now Thanks. I did  it in different way to get the location :)
link

answered 2011-12-10 at 02:47:44

Abdullah15's gravatar image

Abdullah15

Thanks
link

answered 2011-12-10 at 03:39:33

Abdullah15's gravatar image

Abdullah15



That is exactly how I told you to do it


see my post   ID:37265690  above:


>It will create .jar for you and it will write in teh resukts area something like this:

>To run this application from the command line without Ant, try:
>java -jar "C:\netbeans_projects\Converter\dist\Converter.jar"

>(you may have another path of course)
link

answered 2011-12-10 at 03:41:11

for_yan's gravatar image

for_yan

I might miss understand you but  you helped me step by step. I know my self I need more time to get everything and think.
Thanks
link

answered 2011-12-10 at 03:44:58

Abdullah15's gravatar image

Abdullah15

Yes, and please read  posts more attentively - it is better not to rush and just calmly follow the steps.
If you don't understand some piece - rather ask questions
link

answered 2011-12-10 at 03:49:43

for_yan's gravatar image

for_yan


Thanks CEHJ: for providing me this information. I will continue learn Java until I stand on my feet.
link

answered 2011-12-10 at 03:58:08

Abdullah15's gravatar image

Abdullah15

for_yan: I will ask in future and I am trying to do my best to get your idea because if I asked you many questions you might bother you and you will not help me next time.
link

answered 2011-12-10 at 04:11:43

Abdullah15's gravatar image

Abdullah15

No, don't afraid to ask questions, but read reponses attentively
link

answered 2011-12-10 at 04:14:21

for_yan's gravatar image

for_yan

I will next time.
link

answered 2011-12-10 at 04:16:42

Abdullah15's gravatar image

Abdullah15

Is it possible to run it on any Computer Without NetBeans. I mean it is enough just take copy of two files "Converter1.Jar and Converter1.fbat?
link

answered 2011-12-10 at 04:19:22

Abdullah15's gravatar image

Abdullah15

Sorry "Converter1.bat"
link

answered 2011-12-10 at 04:25:00

Abdullah15's gravatar image

Abdullah15

Yes along with these files you only need to have Java runtime to be installed. Nothing of netbeans is necesary - it is already included in convrter.jar
link

answered 2011-12-10 at 04:25:37

for_yan's gravatar image

for_yan

How to use Java runtime it just pit it with converter.jar. I downloaded now what I should do with it?
link

answered 2011-12-10 at 04:40:00

Abdullah15's gravatar image

Abdullah15

>>
Create text file in this folder  and rename it into Converter.bat
Open it with the Notepad editor

Place the line

java -jar Converter.jar

in this file

Save the Converter.bat file
>>

Why is a batch file necessary?
link

answered 2011-12-10 at 04:54:59

CEHJ's gravatar image

CEHJ

I guess to make the code work  without go to NetNeans program and compile the code.
link

answered 2011-12-10 at 09:00:53

Abdullah15's gravatar image

Abdullah15

No - nothing to do with compilation
link

answered 2011-12-10 at 12:08:56

CEHJ's gravatar image

CEHJ

After you download and install  Java Runtime Environement on any brand new computer and then put the Converter.jar (which you can find in that dist directory underNetBeans ) into any folder together with the .bat file haveing this line
java -jar Converter.jar

Then once you double-click this .bat file your applicatiomn will run.

That's why I was trying to show how to put it into another folder, rather than directly using it within the NetBenas folder structure
Jut to show you that it is no longer dependent on NetBeans

link

answered 2011-12-10 at 12:22:48

for_yan's gravatar image

for_yan

a. normally you shouldn't need a batch file
b. (and more importantly) about the only good reason for doing what you originally mooted (making it into an executable) is to make certain it runs, with or without a JRE. I'm afraid the methodology suggested to you doesn't address this problem. Using the suggestion i gave you will smooth over that problem
link

answered 2011-12-10 at 14:15:33

CEHJ's gravatar image

CEHJ

The batch file is the simplest way how you can accomplish your point and the point is that most of Windows users do not know about the
command line, would not be able to rememeber and to type the line
java -jar Converter.jar

Once you put it in the batch file - they can double-click on this file or on its shortcut on the desktop - and this is the completely
familair experience to the users - they usually don't care if they are clicking on .bat file or on .exe file or on any other icon to start the application.

It is true, there are lots of other ways to achieve this goal including  WebStart, or packaging java applications into .exe
files using either free or commercial wrappers, however all those oher options are certainly much more complex and most of them require to use and learn additional sioftware.
If you are developoing software for a limited group of users - say within your nearest departement
and all those users can access the same file share then the batch file as the most simple solution has many advantages
over the more complex stuff.
By the way you normally do not need to install java runtime on each computer, as most of
pc's now have java pre-installed and especially if you are working in corporate environemnt
then your IT department will usually take care of installation of Java Runtime at some point when computer is given to the
user. With the batch file there is also a simple way of being independent of local JRE or its existence; for the beginning you can rely on its exitence.
For you at the beginning of your java learning that would certainly be a very useful ability to know how to do it with the batch file
and to fully understand it - more or less the way we did it with you.
If you need in future you can expand to much more sophisticated systems, especially if you start developing applications
for big groups of users spread over various  locations, let alone the commercial software.
So each situation shoudl use its most approprate form and if you  apply methods developed for commercial software dstribution
for situtaions which are not close to that kind of environemnt that will just result in waste of resources and too steep a learning curve.

SO review the way you diod it with batch file, try to do it on another computer if you have such option, see for yourself that itnis indpendnt of netbeans,
and ask questions if something is not working.





 
link

answered 2011-12-10 at 14:25:57

for_yan's gravatar image

for_yan

>>Once you put it in the batch file - they can double-click on this file or on its shortcut on the desktop

You don't need to put it in a batch file as i said above. A simple double-click on the jar icon should be enough

PLUS the fact that a batch file is not cross-platform, which rather defeats one of the principle points of Java in the first place
link

answered 2011-12-10 at 14:55:11

CEHJ's gravatar image

CEHJ

Taht is true - excutable jar which we created with you will work even without batch file - just by double-clicking.
There are though many situationwwhen you use normal java start up when you have a classpath and refere tio the main class.
The .bat file will cover these sitautaions also. And if you are developing just for a few peopel and therefore may rathe often
change your code or pieces of it, it is siometimed convenient not to put it into any jar file but use the whole class directories, therefore
to know about the batch file is very useful thing.

As to other operating systems - you should really not bother about it.
If you are developing on windows, your users are on windows, it may happen that you'll need
to develop for other operating systems in the next world. No sense thinking about it now.
Besides when you need it you'll find that all operating suystems have similar concept, the syntax may onlty be a little bit different.
link

answered 2011-12-10 at 15:00:06

for_yan's gravatar image

for_yan

>>As to other operating systems - you should really not bother about it.

Having programmed in many different languages on different platforms, i can say confidently that if you're NOT interested in your code being cross platform you probably shouldn't be using Java in the first place
link

answered 2011-12-10 at 15:11:47

CEHJ's gravatar image

CEHJ

There is absolutely no doubt that  overwhleming percent of all programs written in Java will never be used on any other system than Windows.
link

answered 2011-12-10 at 15:20:32

for_yan's gravatar image

for_yan

And I very much doubt taht there are many really big programs which are used on different operating systems
without a single change in the code base, and  especially in such areas as deployment, etc.
Other than in world of applets cross-platform stuff is more a slogan than anything practical.
And even for applets - stlll a huge majority of folks are browsing from windows, and applets will still not work for mobile browsing.
So that was initial slogan which played a role in Java's initial fate, but is mostly not relevant any more.
No sense to make any sacrifices or invest much time in pursuing it.
link

answered 2011-12-10 at 15:23:23

for_yan's gravatar image

for_yan

That maybe so but that's a different point. Users will certainly find it more difficult to use the code where they choose if the developers of their code are encouraged to depend on platform-specific code in order to start it
link

answered 2011-12-10 at 15:31:14

CEHJ's gravatar image

CEHJ

>>That maybe so but that's a different point.

That of course is in response to comment  http:#37268108 The one following it is simply wrong
link

answered 2011-12-10 at 15:32:31

CEHJ's gravatar image

CEHJ


>The one following it is simply wrong

Well that is your personal opinion.
Look around at the life outside beyond what is written in Java textbooks and maybe you'll consder changing it.

There are thousands people in our company; if we are not talking about mobile devices, 99% of them never
worked a single minute on any computer other than Windows or Mac - so I don't know how many GUI applications
are really used on any other systems, but the percentage is defintely very low.

Even when it comes to server side - even if you have say Tomcat written in Java
you'll never see that you can take the same bunch of files and without any changes
use them as the code and surounding stuff for Tomcat runing both on Windows and on Unix.
It always make snese to make a few modification which will make use on particular
platform much more convenient.
So this cross-platform talk does not work in real life, but there is after all  no need for it.

Not even talking about the stuff which Abdullah15 is writing. They definitley should not be concerned with "cross-platformity".
 

link

answered 2011-12-10 at 15:35:38

for_yan's gravatar image

for_yan

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 12/09/2011 03:30

Seen: 470 times

Last updated: 12/09/2011 07:41