Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Trying to create a .exe file from a .jar file

 
Ranch Hand
Posts: 56
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good afternoon,

Having looked up advice on how to do this a lot of advice seems to tend towards downloading software to convert a .jar file to a .exe file. I am particularly keen to be able to have a folder which I can email to friends so they can use my programs.

Guidance online has led me to download a program called Launch4J.

Having followed steps religiously I must be missing something, as the exe file produced does not seem to run.

It does not produce an error, I simply double-click and it does nothing.

I only have two classes with one method in each. My main class/method is:



My second class/method is:


When run from within Eclipse it brings up a window with a black background which I can run, click on 'Test' and it closes it down no problem.

Is there any guidance I can follow that can enable me to basically enable this to become a sharable program which I can simply email to others?

Obviously this is just a test but I'd like to get it working!

Thanks in advance for your help.
 
Marshal
Posts: 75676
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't send an excutable .jar, I presume? That would necessitate them having a Java® runtime, however.

Moved to ”general” forum as too difficult for ”beginning” forum.
 
Greenhorn
Posts: 8
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having run into this same situation a few years ago when I was first learning Java, I thought I would share a few things I learned/discovered in the hope that they will be helpful to you:


1. Because there are people in this world who wish to distribute malicious .exe files, it has become extremely difficult to distribute homemade .exe files. When I tried to do this a few years ago I ran into roadblocks at every turn. I found I couldn’t email them to others, I couldn't share them using file sharing sites, and I couldn’t install them without them being flagged as potentially malicious. I could discuss at length about how unfair and frustrating that is to those who don’t want to make money from their programs, but that topic is a can of worms for another post and another day.

2. Eventually, after many months of trial and error and frustration at every turn, I gave up on trying to distribute my programs as .exe files. I found that it simply wasn’t worth the trouble and expense. If you are working inside a business that already has the ability to sign .exe files, or you have already built up a reputation over many years, then distributing your program as a .exe file might make sense. However, in your situation, I would strongly suggest that you avoid the trouble of trying to distribute a .exe file.

3. If you are just trying to share your code with others as an example of what you have built, I would suggest that you investigate the following alternate:
At the moment that I am writing this, it seems that https://repl.it/languages/java10 will allow anyone, (with or without an account), to paste in Java code and run it virtually. This means that your friends can simply go to this website, paste in your code and run it. They won’t have to mess around with downloading Java or installing anything that they may or may not trust. It also means that even if you were distributing something malicious, the potential damage it could cause to their computer would be limited since they could simply close their browser. Don’t get me wrong. There is no such thing as 100% security. However, asking your friends to go to a web page is a lot less intimidating than asking them to install Java, especially given Java’s history as a vector for malicious exploitation.

At the moment, that website isn’t the greatest when handling graphical programs, and I haven’t tried it on a mobile device, but at least it will give your friends some form of visual output when viewed on the desktop. You might be able to experiment further and get better results than I did. Here is a slightly modified version of your code that seems to at least run, albeit with warnings, in the aforementioned website:

In the file named Main.java paste in this:


And create another file named MainMenu.java and paste in this:



Beyond this particular website you might be able to find other sites that perform a similar function.

I hope that helps,
 
Saloon Keeper
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you can build an EXE from a JAR as a general rule. Since Java does not produce native object code, you'd have to bundle in a JVM with the app and that would be A) very large and B) likely to have legal consequences. Definitely have legal consequences if you tried doing it with an Oracle JVM.

One approach to do more or less what you have described is to use JNLP/Java Web Start. With that, you can direct people to click a link and client-side code would check a local cache for a copy of the JAR in question and if there was no local copy, download and cache one (thus giving better performance than it you had to download every time). This approach was used by the ArgoUML project, for example.

Unfortunately, I think that it has been deprecated in modern Java releases, you so should check on how feasible that is. In any event the user does have to have a compatible JVM already installed locally, since, again, there can be licensing issues.

For the most part, locally-executable apps have become secondary these days. Web-based apps don't require much, if any, special infrastructure on the client machine and you don't have issues with hardware/OS portability (if you design properly), or making sure that everyone's copy of the app is up to date and properly patched.
 
Roger Frybarger
Greenhorn
Posts: 8
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:... likely to have legal consequences. Definitely have legal consequences if you tried doing it with an Oracle JVM.


Yes. That was definitely one of the many issues I ran into.

Also a related piece of advice: If you ever do try to experiment with creating .exe files, I would strongly advise that you avoid running them in your main system in case things go... ummm..... Badly. I would advise that you install a virtual machine and run your experimental .exe files in there. That way there is a bit of a barrier preventing your main system from potential damage.
 
Lookout! Runaway whale! Hide behind this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic