I am new to Java and is using Eclipse.
Whenever I have build a Java (JFrame) project successfully on my PC and when I deploy the java project files to other users, I have to compile the projects on other ppl's PC before they can really use it.
Is there any convenient way to tackle this? i.e. When I placed those Java files to a shared folder, all other users (new/existing) can execute it on their PC.. (juz like .exe in MS Window) Actually how is the practice outside?
The best way to distribute a desktop app. to users is Java Web Start. It requires some extra work from us the developer, but is a breeze for the end user.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
You can use Eclipse to create a JAR file for your project, and it will generate an executable JAR that the others can run. For more on creating JARs in Eclipse, see this.
Related
I read here that it's possible to deploy a JavaFX application into a Web Browser:
embed-a-javafx-application-in-a-html-webpage
Now I got stuck at the beginning when he talks about using the java packager to create an executable .jar file. I'm using Maven which uses JavaFX 18, so I followed this tutorial on how to package a java project
java-packager-with-jdk11
Here I got confused with the tools he uses. I downloaded the listed tools and moved the jpackager files into the according directories. Still in cmd it gives me an "Error during initialization of boot layer": jdk.packager not found.
It's pretty worth it knowing how to create a Package from a Java Project, but is this the proper way?
tl;dr
No, not realistic.
You have a choice of alternatives.
Legacy technologies
That page uses legacy technologies, Java Web Start and Java applets.
Java applets have been phased out by all web browser makers, so Oracle consequently decided to phase out the technology. Java applets were first deprecated in Java 9, and later deprecated for removal in Java 17.
Oracle no longer expects end-users to have a standalone JRE or JDK installed on their computer. So Java Web Start is no longer available by default for the consumer market. Java Web Start is no longer included in Java 11+.
However, an open-source implementation continues in the OpenWebStart project. For some environments, such as corporations or schools where the installed base of computers is centrally managed, OpenWebStart may be a useful way to distribute apps.
Ship your app with JVM bundled
Oracle now expects desktop apps and mobile apps to bundle a JVM within their product. This does mean the app must be built in editions, one edition for each supported chip architecture and OS, but also allows the app to be tested with the same JVM that will eventually run the app.
For more info, see the Oracle white paper (PDF format), Java Client Roadmap Update of 2020-05.
New tooling is available to support this JVM-within-app packaging:
Java Platform Module System (JPMS) in Java 9+.
jlink in Java 9+.
jpackage in Java 16+.
Search Stack Overflow to learn more about packaging JavaFX/OpenJFX apps for distribution. Many Questions and Answers have already been posted on the topic. The topic is rapidly evolving, including cutting-edge approaches such as using GraalVM for ahead-of-time compilation to run native.
Vaadin Flow
If you want to build a single-page web app written in pure Java without you needing to learn HTTP, HTML, CSS, JavaScript, WebSockets, Push, etc., consider using Vaadin Flow. This open-source framework is based on venerable Jakarta Servlet technology.
You write Java code similar to that in JavaFX, defining forms by specifying widgets arranged with layout managers. Vaadin Flow then auto-generates the needed HTML+CSS+JavaScript to render the user interface remotely in the web browser while maintaining the state of your app on the server. Pure Java on server, no Java on client.
I know that I can convert a Swing application to an Applet or a Java Web Start application. Is it possible to do the same with an application that's not Swing, say Qt using Java?
What I'm really looking for is a UI framework using Java that's as cross-platform as possible and also has a rich set of UI functionality. Being able to run the application as either a desktop or a Web application would be preferable.
What I'm really looking for is a UI framework using Java that's as cross-platform as possible and also has a rich set of UI functionality.
Assuming a desktop deployment, the three major frameworks are Swing, SWT and JavaFX.
Try the JavaFX Ensemble sample to see if that technology would suit your needs.
I know that I can convert a Swing application to an Applet or a Java Web Start application. Is it possible to do the same with an application that's not Swing, say Qt using Java?
QT is native code that doesn't run on the JVM - it is not a Java UI framework. Applet and Web Start programs require a Java class as their entry point. Any use of QT is such a scenario would require a Java <=> QT adaption layer and I am not aware of the existence of any such thing - you would probably need to build it yourself based on a technology like JNI.
Being able to run the application as either a desktop or a Web application would be preferable.
See the JavaFX deployment guide for various JavaFX deployment options and the Swing deployment guide for various Swing deployment options.
The definition of Web application is pretty nebulous. Here are some distinct scenarios:
You are restricted to just html5 => produce the html on a server to
distribute to the client.
You want html launching a Java
application => then something like WebStart in combination with the
Java Deployment Toolkit can be used.
You will be rendering a
JavaFX application inside a browser window => then use a browser embedded app.
There are many pitfalls for embedding java applications is web pages (just use google to discover some of them).
What I have done in one of my projects is develop the application as a web application and then generate a installable to distribute my application. This has great benefits:
It can be installed in a server and publicly available. Just as a normal web application.
It can also be installed in a desktop.
I used "Jetty" to embed the web server in my application and be able to run the application as a stand alone in desktop environment. The slogan of Jetty is "Don't deploy your application in Jetty, deploy Jetty in your application."
Also I used "IzPak" to package my application in a executable JAR for installation. If you want to make that JAR easy to install for people who might not have installed Java you can use launch4j which is a tool that wraps the JAR into an EXE. So it can validate first if the computer has already Java and if not inform the user that he needs to have Java installed to proceed. The only drawback of this is that if you wrap your application in an EXE you are limiting the portability to other platforms, but that's your decision according to the requirements.
Java Web Start apps can contain native libraries, so yes you should be able to convert an app using Qt (assuming the bindings exist) to a JWS app.
Applets on the other hand are tricky to make work with anything other than AWT/Swing, since you have no control over the creation of the top-level window.
If you want to use Qt you would first have to make Qt bindings for Java as they are not currently functional.
If you want to use Qt bindings from a Java Applet you will need to make your bindings an installable extension which would be a potential security risk unless you know what you are doing. You would also have to get the user to install your extension. Also IcedTea-web which are the FOSS plugin shipping with Linux will not load an extension. So if you want your extension to work on Linux you will have to fork IcedTea-web and make your own plugin.
So the short answer: Stick to Swing.
As I know there are two standard ways you can distribute a Java desktop application:
Through a runnable jar file
Through a bat file which calls a jar file to begin execution
I want to know what is the best way among these methods and what are the relative advantages and disadvantages?
The list is missing the best one!
..
..
Java Web Start.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
In case it is not clear, I vote JWS as the 'best' from a user point of view. The details of the advantages are pretty much expressed in the 2nd paragraph of the description, but also the last sentence of the first. Not to forget the 1st sentence of the next paragraph..
By default, an applet-like security sand-box is applied to code launched using JWS. ..
I think runnable jar would be a good option for desktop application. As I am using it for my desktop application is more comfortable and user friendly.
I think it will depend on who are the users of your application.
If the users are non-tech people you better go with a runnable jar because
they are less likely to pass an argument to your program.
In case they are your team members or other tech people, you may give them a .bat
to play around with your app.
For Windows, wrappers like Launch4j could be considered.
The open source software always use .bat or .sh file to distribute a java application.I think this way would be a good option.
I have created a GUI application using Netbeans and it has a connection to a database( localhost).
Now I want to be able to distribute it as software.
Is there any way to produce a setup file for the Netbeans project? and how can I distribute a Netbeans project which uses a MySQL database?
how can I distribute a Netbeans project which uses a MySQL database?
You might want to get familiar with NSIS. NSIS will enable you to automate the installation process.
Your installation process will have to do the following:
Check that the Java Runtime Environment is the same version you used or higher.
Install your application JAR file somewhere.
Install the MySQL version that your application requires
Create and initialize the tables for your application.
Your installation process can do the following:
Create an uninstall executable.
Add an icon so that the user can start your application.
This installation process will take some time to develop and test.
You probably want to use an installer. Have a look at:
Install4j
Installshield (commercial)
Advanced installer if you target only windows platforms
There are many others but I hope this can help you...
Use the solution made by the suppliers of Java - Java Web Start.
The deployJava.js (described in the linked page) ensures the user has the minimum JRE needed to launch the app. & MySQL.
Launch the app. using Java Web Start.
Reference an installer-desc extension for installing the DB. Store any set-up details into the PersistenceService for later use.
JWS works on all major platforms for which J2SE is available and also provides..
..many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
I'm working on Desktop applications. I'm using JFC/Swing to build the application.
Now I want to build application that can be upgradable by changing some jar files, instead of installing entire application again.
I'm stuck with some basic steps. I want to add JMenu from various jar files, so I dynamically added those jar files. Now my issue is that, I want to perform some functions like adding JInternalFrame to the main class, which loads entire jar files. I am not able to achieve it.
Please help me with this issue, and suggest any idea to make it possible.
Now i want to build application that can be upgradable by changing some jar files, instead of installing entire application again.
Java Web Start..
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
you can do it easily using URLClassLoader, you can see s simple example here:
http://snippets.dzone.com/posts/show/3574