Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Making stand alone java programs?  RSS feed

 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I wanted to train my java skills a bit and make real useful apps that people are going to like and use. Cmd programs are just ugly and not user friendly!
I learned that I can write a gui program and turn my file into an executable .jar file, then distribute my program for people, through a website may be

I really like the idea of .jar files,
but it just doesn't feel right!

Im a windows user, and I have just never seen real life .jar programs! Only .exe!
is this how java programs are supposed to look like? or am i missing something?
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad, distributing via .jar files is pretty common. It's also one of the long list of happy accidents that resulted when what is now "Java" was given that name instead of the original "Oak." A Java ARchive is a jar full of Java.

Of course, a .jar files isn't an executable. It's a list of instructions read by the Java Virtual Machine, which means the computer you are going to run your .jar code on must have a Java Runtime Environment (a "JRE") installed on it. These days, quite a few of them do. If not, you will have to distribute one with your .jar file, which is a bit of a headache.

But, yes, using .jar files is a good way to let others run your code. See this tutorial for more guidance.
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ahmad, hello, welcome to standalone Java programs.

What you have stumbled onto is the subject of some debates out in the world of Java. Here's a poll someone put together on this very topic. http://www.coderanch.com/t/658288/md/Poll-develop-maintain-desktop-applications .

You are correct in saying that you don't often see just .jar files delivered to people. If you hand someone that, they will then have to associate that (somehow) with their JVM/JRE. I have solved this in the past, by bundling a JRE with the jar file, and providing a batch script to run it. Even that may be too complicated for some. They like to be able to click once and start the code.

That being said, one of the better ways to distribute programs written in Java is called "Java WebStart", or "JNLP" (Java Network Launching Protocol). You can read up on that, and it will help you to deliver Java applications over the web, so that users can run them locally. There are a lot of other convenient things being done for you there, that you may not yet have thought of, if you are new to this. Applets are a possibility, but they come with other issues, and are often seen as obsolete never-was'es. As an aside, I have written successfully-used Applet code. It was usually for internal-to-organization use.

Another thing you can do, is to write applications using a framework, like NetBeans RCP. If you do that, you will basically be building a .exe on top of that framework. It has some convenient things for you, such as a consistent and powerful user interface, and lots of facilities to exploit. If done using the NetBeans IDE as well, it will create for you the means of packaging your application as an executable for Linux, Windows, and/or Mac OSX.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Foster wrote:...one of the better ways to distribute programs written in Java is called "Java WebStart", or "JNLP" (Java Network Launching Protocol).


That might be a non-starter, L. I just happened to read this today:

Horstmann, Cay S. (2014-01-10). Java SE8 for the Really Impatient wrote:
As of today, Oracle signals that it is no longer focused on securing home users’ Java applets and Web Start applications (collectively called rich internet applications, or RIAs).
...
If you maintain an applet or Java Web Start application for home users, the message is clear: Move away from it. If your application serves a specialized audience (for example, software development, image editing, or document processing), make your users install Java or bundle a JVM with your installer.


There are some other depressing warnings Dr. Horstmann has about deploying Java desktop applications, as well as a prediction that migration to tablets that don't have Java-enable browsers means that Java's future is in the corporate setting. I'm not happy about that, but that's what he said.

 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad Auada wrote:Im a windows user, and I have just never seen real life .jar programs! Only .exe!
is this how java programs are supposed to look like? or am i missing something?

I suspect the latter.

The fact is that .jars and .exes are two very different animals. The latter is a Windows-only file, designed to be run ONLY on a Windows machine and probably only lacking a few standard .dlls to work.

A jar is a completely different kettle of fish. It is (usually) a directory tree of "p-code" files, in "archive" format that need a JVM (or JRE) to run.
The business of the JVM is to read the p-code and translate it into executable (.o or .exe type) code that can THEN be handed off to the local OS - be it Windows or Linux or Unix or Android.

The reasn for this is that Java was designed for platform-independence. If I write and test my program at home (and I run Linux on my home machine) I can be confident that it will run on any machine that has a JVM (or JRE), including Windows.

Microsoft have tried, with things like C# and .NET, to get into this market; but you know what? They're just not very good at it.
I guess a 70% market share will do that for you. Better the client you know...

So in the meantime, Java is the "poor sister" when it comes to Windows-only. MS don't care because Java is a major competitor in a lot of different areas. There are products out there - even free ones - to convert jars to exes, but how good they are I couldn't tell you, because I haven't used one in 10 years.

Hope it helps.

Winston
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This "bundled JVM" approach actually lends support to the use of NetBeans RCP framework, which easily lets you do that, to make your executable.

Thanks for that valuable (and startling) information, @Stevens.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad, everything Winston has said is (as always) correct, but I want to add some precision to this statement:
Winston Gutkowski wrote:The business of the JVM is to read the p-code and translate it into executable (.o or .exe type) code that can THEN be handed off to the local OS - be it Windows or Linux or Unix or Android.

The JVM is a .exe that reads the p-code and, more or less, simulates a central processor that has the p-code as its instruction set. It does this by executing instructions that are appropriate to the OS and actual processor hosting it. But it doesn't ever actually create a .o or .exe file for you. It simply reads your .jar (or .class) file, and interprets its contents appropriately for the platform it's running on.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Foster wrote:This "bundled JVM" approach actually lends support to the use of NetBeans RCP framework, which easily lets you do that, to make your executable.

Thanks for that valuable (and startling) information, @Stevens.


I was startled too, L. Dr. Horstmann is pretty heavily invested in Java (as the author of several books about it), so this criticism from him can only be sincere. Now, he does offer some pointers on how to use manifests to keep .jar files secure, so all may not yet be lost.

Regarding bundling a JVM, he says that this puts you on the hook for delivering your own updates, as he says Oracle has never come up with a good way to do that automatically. That surprised me, since my (Windows 7, now 10) machine(s) seem to pop up a little "Java update ready" message every other week. Maybe that only comes with the full JDK, or a download from Oracle itself (which, continuing in his unvarnished truths about them, Dr. Horstmann says leads to them trying to load that annoying Ask.com toolbar into your browser).

Now, deploying updates doesn't sound too odious. One's application could be bundled with a JRE known to work with it, and, even if a new JRE comes out, there is nothing inherently wrong with having more than one JRE on the same machine. If your installer doesn't find one (or one it likes), it can go ahead and install its own, in a folder local to the application, and just use that for its own needs. Even if another JRE comes along, perhaps even a more recent one, so long as your application works with the JRE bundled with it, and continues to invoke that one when it runs, you should be fine. If you want to deploy updates to the JRE you bundled when Oracle publishes them, you're really no worse off then if you had to deploy an updated .dll (either one that MS provided, or one your wrote for a native app), or just an updated .jar for your own application. I mean, in the end, an update is an update, and updates are fact of life for software.

I use NetBeans, but have not previously heard of RCP. Got a link for me?
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a link https://netbeans.org/features/platform/. RCP stands for Rich Client Platform. It is a special type of project you can create from your NetBeans IDE.

Do New Projects / Categories: NetBeans Modules / NetBeans Platform Application.

You can see other sub-module types next to that one, including Module, Module Suite and Library Wrapper Module. There are tutorials out there for migrating to this type. I think this is a similar concept to something you can do in Eclipse.
 
Liutauras Vilda
Marshal
Posts: 4641
318
BSD
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad Auada wrote:So I wanted to train my java skills a bit and make real useful apps that people are going to like and use. Cmd programs are just ugly and not user friendly!
You may be right that command line programs are not that user friendly, but probably you should start building your desktop app right from there.
To visualise this, you could think of starting the car with touching two starter wires rather than pressing starter button - it is of course easier and more user friendly, but it does not change the way car engine starts. Pretty similar is GUI, it solves usability issues, but probably not much program usefulness and how the program works itself.

Before you start, you may want to read about:
1. MVC (Model View Controller).
2. JavaFX or Swing.
2.1 JavaFX Scene Builder or Window Builder plugin for Eclipse (if using) to ease Swing GUI app building.

Sorry for a slight off topic post, but thought that might could help you a bit.
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
things are clear now! Thanks for the tips guys!
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to distribute JAR as a Win EXE - especially to users who may not know what to do with a JAR - use http://launch4j.sourceforge.net/ to wrap your JAR as an embedded resource in an EXE. It can also download a JRE if it's not already installed on user's machine.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik Shiraly wrote:If you really want to distribute JAR as a Win EXE - especially to users who may not know what to do with a JAR - use http://launch4j.sourceforge.net/ to wrap your JAR as an embedded resource in an EXE. It can also download a JRE if it's not already installed on user's machine.

Apparently, NetBeans has some built-in support for this, as well. It's in the project context menu, under Properties/Build/Deployment. You can check a box that adds a new entry to the context menu, "Package As..." This gives you five choices, four of which need an add-on to run. The one that does run appears to build a sub-tree that includes a .exe you can run to start your Java application, but I don't think it includes the java.exe itself. It does seem to include a lot of other files one would expect to be in a JRE, but no java.exe. I will explore this further and report if I find out anything useful.
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Stevens, you could, with a single click, make an installer. NetBeans has a framework to deploy partial updates, for anything delineated as a plugin. Users can open a panel off 'Help', and can see what has been updated since last time, and easily pull those updates. Play your cards right, and you would only seldom have to redeploy an entire executable.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Foster wrote:@Stevens, you could, with a single click, make an installer.


Don't keep me in suspense, L. What do I click?
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Stevens, go to your 'Module Suite project' in the Projects pane (left hand side, with a Tree of projects). Menu-click that. Package-as/Installers.

OK, so you had to click menu click AND select-click. Sigh!

The output will be in a subdirectory of the module suite project called "dist".
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just done this on a fairly large project. Over a span of a few minutes it made all these installers.


Have fun!
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... I get this:

ant -f "C:\\Shared Documents\\Local Google Drive\\NetBeansProjects\\WindowsExe" -Djar.archive.disabled=true -Dnative.bundling.type=installer build-native
Detected JavaFX Ant API version 1.3
Execute failed: java.io.IOException: Cannot run program "iscc" (in directory "C:\Shared Documents\Local Google Drive\NetBeansProjects\WindowsExe"): CreateProcess error=2, The system cannot find the file specified
Execute failed: java.io.IOException: Cannot run program "candle" (in directory "C:\Shared Documents\Local Google Drive\NetBeansProjects\WindowsExe"): CreateProcess error=2, The system cannot find the file specified
C:\Shared Documents\Local Google Drive\NetBeansProjects\WindowsExe\nbproject\build-native.xml:438: Error:
JavaFX native packager requires external Inno Setup 5+ tools installed and included on PATH to create EXE installer. See http://www.jrsoftware.org/
JavaFX native packager requires external WiX 3.0+ tools installed and included on PATH to create MSI installer. See http://wix.sourceforge.net/
BUILD FAILED (total time: 0 seconds)

Looks like I have to install some installer installers .
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:

Looks like I have to install some installer installers .


installception?
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad Auada wrote:
Stevens Miller wrote:

Looks like I have to install some installer installers .


installception?


Brilliant. I shall find a way to use this word in a sentence, once a day.
 
navneet gautam
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to learn how to make standalone applications in java then you can visit to http://docs.oracle.com/javaee/6/tutorial/doc/gkcpv.html and one more thing is that you can write the codes in netbeans so that you can easily get .jar file which are executables and easily run on other platforms.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:. . . rilliant. I shall find a way to use this word in a sentence, once a day.
But only in MD
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, all.
I was just looking for something unrelated, and stumbled upon this. There is a 'community' on Oracle's site for Java Desktop. I have not explored this, so I do not know how active it is. You may have to login with an Oracle account.

https://community.oracle.com/community/java/java_desktop/java_desktop_applications

HIH
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the last activity was two months ago, you can hardly call that active.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!