How can I pack a Java application and MySQL installation files in a single exe file? Can I install the MySQL files automatically in background (or without any inputs from user)? This is just to simplify the installation procedure.
Java is cross platform, MySQL isn't, so you'd have to create various installers for multiple platforms with different MySQL binaries. If you want to include MySQL source code for non Windows systems, then that's another story... so I assume you want just an installation for Windows.
First of all, get an installation software that you'll feel comfortable with. There is a nice list of free and non free installers on Wikipedia.
Second thing, you can do a silent MySQL installation. How it's done is explained here.
But note that doing a silent MySQL installation without user's permission doesn't sound too good to me, since MySQL isn't exactly lightweight software and you might mess up something if a user already has MySQL somewhere installed.
So, by doing this, you have to be extra careful to check if port 3306 is already up and running (default MySQL port), and other sanity checks to see if there's a possibility of another instance lurking in the background.
It would be better if you at least informed your user that MySQL will be installed. Think about these details, because they might be dealbreakers so some of your users.
Use Java Web Start to launch the application.
JWS offers an ExtensionInstallerService that can be used for installing MySQL. Here is a small demo. of the ExtensionInstallerService.
Related
i am currently writing a game on javaFX and i have plans to post it in the website i run in the future (end exploit the Ads while at it). The problem is that after searching around a little it seems there is no way to run a java application on a browser.
Allowing people to run it through the browser would really help sharing the program.
My question is: is there today(2018) any way to run a java application through the web? Though i like java, no browser support seems like a really, really bad idea.
Oh, i also heard of Java Web Start. Although it looks like it is just avoiding the problem (not running in the browser) it seems like a good way to share an application. The problem is that it seems it is (Will be?) deprecated? I am helpless, it is like java isn't even trying anymore...
PS: If it makes any difference my game would be a 2D game with 3rd person view. It will also require some server stuff since players will create "arenas" that others can challenge. I would say my game wouldn't be "simple".
Java Web Start does the job very well—if you are willing to pay for a code signing certificate. (They’re a lot more expensive than regular SSL certificates.) The idea is that a user clicks on a hyperlink on your page, which causes the user’s Java installation to launch your application (possibly after installing it). This requires users to have Java installed beforehand.
If you don’t have the resources or desire to go with a code signing certificate, you can look at https://docs.oracle.com/javase/9/deploy/self-contained-application-packaging.htm. It allows you to create native installation packages for JavaFX applications. The disadvantage: You need each platform to create an installer for it. Meaning, you need Windows to create a Windows installer, OS X to create an OS X installation image, and Linux to create a Linux package. Some may also require signing using native tools.
Java 9 includes the jmod and jlink tools, which are capable of creating a file tree with an executable shell script or .bat file. A major advantage is that you can build such a tree for any platform, regardless of your own platform, if you unpackage the foreign platform’s JDK on your machine. Another advantage is that the user doesn’t need to have Java installed at all. A disadvantage is that the script requires a terminal, unless running on Linux.
Of course, you can just go the manual route and distribute a zip file which contains your .jar file(s), a shell script you’ve written, and a .bat file you’ve written. It’s not elegant, but it’s better than nothing. But it may trip up some non-technical users.
There exist a number of tools which create a native executable from .jar files, but I am not familiar with them (and I prefer to avoid third party tools unless they are truly necessary).
Whatever approach you choose, the answer is the same: You distribute something on your web page which the user downloads and runs. Aside from the download process, the browser is not involved.
What you can’t do is have users run your application inside the browser. That is deprecated, with good reason: It’s a disaster for the browser performance, for the Java runtime, for security, and for the user experience. And Firefox has all but banned plugins, so you’d be locking out a substantial percentage of users.
I read SO q&a about launch java as windows service wrappers, but can't find/choose product, suitable for my requirements :
Wrapper reads all java launch parameters from config file. In registry must be only commands to run wrapper itself - path to exe and maybe path to config. Always grant admin rights to change app parameters in registry is not comfortable.
Working dir and path to application also must be in config. I want to place all wrapper files deep into program, because user not intrested in it.
No dependencies(.net, python, etc). I don't want to extend requirements of my program.
Free for every windows OS, include win64.
Simple and lightweight. Size of my program with all 3rd party jars is 12Mbytes. I don't want to add 20Mbytes wrapper.
Automaticaly restart if app process dies.
Preferably single exe files for all windows platform.
I try and lookinkg throught different wrappers and tired a bit. Best suitable till now is:
jslwin (http://jslwin.sourceforge.net), but i don't know how mature it is(version 0.99). Also parameter lists in config is a bit complex(need to edit parameters quantity).
winrun4j (http://winrun4j.sourceforge.net), but i don't know how mature it is(version 0.45). Also it needs a special class for working as a service.
Also i try or look throught:
YAJWS (http://yajsw.sourceforge.net/) too big (30mb), can't make it work with custom files layout.
Advanced Installer (http://www.advancedinstaller.com) too big (50mb).
nssm (http://nssm.cc/) store launch parameters in registry(no config)
winsw (https://kenai.com/projects/winsw) .net required, stops after process dies
commons-daemon, procrun (http://commons.apache.org/proper/commons-daemon/index.html) store launch parameters in registry(no config), can't understand this product, i think it's complex.
jsmooth (http://jsmooth.sourceforge.net) complex and old(last update 2007)
javaservice (http://forge.ow2.org/projects/javaservice/) old (last update 2006)
runasservice (http://runasservice.sourceforge.net/) requires .net
windows rktools - sc, instsrv, srvany (http://support.microsoft.com/?scid=kb%3Ben-us%3B137890&x=16&y=7) - store launch parameters in registry(no config)
jwrapper (http://www.jwrapper.com/) seems not what i need. It packs java program in exe file with JRE. It's not about windows services.
firedaemon (http://www.firedaemon.com/) not free. And maybe it's not what i need.
launch4j (http://launch4j.sourceforge.net/) cool ability "search or download java". Maybe i add something like this to simplify installation, but it is still not about subj.
Java service wrapper (http://wrapper.tanukisoftware.com/) not free for win64.
Tell me please which wrappers suits my needs? Or maybe i think wrong about wrappers above and some of them suits my needs to?
I have had similar issues over the years. Its not that they all are inferior, its that they are all pretty hard to integrate nicely with your own project.
You may want to check out stork: https://github.com/fizzed/stork
It'll help create launchers for your Java console or daemon apps, and they will work across all major platforms. There is also a maven plugin in case you wanted to tie it into your existing build process.
I'm not sure if JWrapper will fulfil all the requirements like 1 and 2 in the way that you want it since rather than you dictating how it does the launch and where it puts things etc JWrapper instead handles that stuff in its own way but it does produce executables for win/mac/linux and more importantly it does support windows service installation as well as macos and linux daemon installation:
http://www.jwrapper.com/guide-installing-a-service.html
The service support though is for paid licenses, the free version doesn't currently support it.
Disclosure: I work for JWrapper
I've been developing in Java using VIM or Notepad++ editors and my java code is on remote linux machine. For small changes, I just putty/vnc to the remote linux machine; for big changes, I use Notepad++ as it has FTP integrated into it. In Notepad ++, I browse the remote files, download the files I want to edit, and just saving the file saves the file back the remove linux machine.
What I'm missing with notepad++ is intellisense, autocode complete, and couple of features that will help me code faster.
I've used Eclipse before where I could code locally, and integrate with version control. However in this case, the files are located remotely and I cannot integrate with version control.
Any one else in a similar situation that has a working solution they can explain?
This is the goal of Eclipse's Target Management (TM) and Remote Systems Explorer (RSE) projects: http://www.eclipse.org/tm/ . Also see their FAQ: http://wiki.eclipse.org/TM_and_RSE_FAQ
You can try something like SSHFS, then you can remotely mount the remote files and treat them as if they were local. If you have a huge project, maybe it's not efficient enough, or if you have a crummy connection. But it's a nice way to bring remote resources local to your machine.
Addenda:
I don't know much about Windows, but I found this link.
Regarding rsync, rsync is a manual after the fact process. With SSHFS you can save or build files, "alt - tab" over to the terminal window and the files are already on the server. We've used it for PHP development. Edit files locally, save the files, tab to the browser on the server and hit refresh -- shazam.
Okay, from the mention of putty I infer you're running Windows.
Choice number one: get an operating system.
Sorry, I just had to say it.
Okay, you've really got two choices.
Choice one: use some kind of distributed configuration management system. Among the possibilities are darcs, bazaar, git, and mercurial. Subversion can access files remotely, so it can do the same thing in limited senses. In all of these cases, you can basically replicate your files to the local machine and return them using simple commands that more or less optimally transfer the files.
Choice two: use a remote file system. SSHFS, and FTP file systems are good. I'd recommend ExpanDrive, which I've used very happily for some years on Macs. It's now available for windows too.
Perhaps the easiest version of this is DropBox, which replicates files across all your machines, including Linux. It's not very real-time, but it doesn't sound like you need that. I use DropBox between home, laptop, and work (on a linux machine) and by the time I've gotten to the office, all my changes at home are replicated.
I have finished writing a Java Desktop application with a mySQL database. I want to make the application run outside netbeans and let it be installed on other computers. I know about building the project and creating the runnable jar file, however this requires me to export the database itself to the other computer I want the application to run on.
My question is two parts:
1)Is there a way I can create a setup file that also installs the database and the application together?
2)Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that?
Thanks
Yes. You can use some setup builder, like InnoSetup, for example. Personally, however, I like giving my customers a zip file, which they extract wherever they like. The executable jar should be able to handle everything by itself (I like it where there is no need to install the software, just unpack and run).
If it is hardcoded, then yes (but, what do you mean by hardcoded? path to file? ip address?). You should use properties or configuration files for paths and other external things your software depends on. The software should read from those files. Upon startup check for presence of such file(s) - if missing, the user should be shown a window in which the config can be entered.
As for deploying MySQL with your code - consider using a server for that, so that your users are not forced to install MySQL, instead they connect to it over the net. If you need the database only for storing data locally, why not using SQLite or a similar, file-based db engine?
The above answers are just suggestions and more-less reflect the way I am thinking. I would be happy to hear from someone with more experience. Nonetheless, I hope the answers help a little :)
I agree with Sorrow.
If I have to use MySQL, it is normally over the net since I don't want to allow my clients pass through the hazzles of installing MySQL themselves. If however you am stuck with using MySQL locally, investigate MySQL unattended installations + NSIS Installer.
If you can use any db you want, I just use javadb/derby. It comes bundled with most Java installations these days and if not all you need is to add a jar file to you application.
As per 'hardcoding' paths, I really don't understand what you mean. You really don't have 'paths' as it were, I am assuming what you mean is connection string. You don't have to hardcode your connection string, just put some parameters in a properties file and construct your connection string from them.
1) Is there a way I can create a setup file that also installs the database and the application together?
See my answer to Java based Standalone application.
2) Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that?
Have the DB installer pop a JFileChooser to ask the user where they want to install the DB. Store that path using the JNLP API PersistenceService. Here is my demo. of the PersistenceService.
on WIN XP SP3 and Netbeans 6.7.1 IDE,
I have installed Java SDK 6.17 which includes JavaDB. I set the JavaDB directory to ...\Java\JavaDB at the Java installation script with %DERBY_HOME% set accordingly and %PATH% including %DERBY_HOME%\bin
Later on I installed GlassFish-V3 Prelude which - surprise surprise - comes with its own JavaDB and silently installs that into a JavaDB directory under the GlassFish path.
Q's
I don't want to have duplicates. Can
I remove one of these installations
without spoiling Netbeans.
How can I verify which of the two
JavaDB's Netbeans is actually using
Can I eventually configure GlassFish
in a way to use the JavaDB I
installed as part of the SDK
Thanks for any hints (as on superuser.com I didn't get any replies :-( )
I don't want to have duplicates. Can I remove one of these installations without spoiling Netbeans.
If really you want to remove one of them, I'd suggest to remove the one that comes with your JDK and to leave the one bundled with GlassFish v3 (GlassFish expects it to be there when using some commands which can be extremely handy, e.g. during development). But honestly, I wouldn't spend too much time for the 4.5 MB extra space used.
How can I verify which of the two JavaDB's Netbeans is actually using
To verify, go to the Services tab, expand the Databases node and right-click on Java DB and select Properties.... You should get the following window:
alt text http://netbeans.org/images_www/articles/65/ide/java-db/javadb-props.png
As documented in Working with the Java DB (Derby) Database, "If you have the GlassFish Server registered in your NetBeans IDE installation, Java DB will already be registered for you."
Can I eventually configure GlassFish in a way to use the JavaDB I installed as part of the SDK
I don't know, but... why would you do that, why is it such a concern, don't you think you're wasting your time? Now, as I said, if this is really an issue, remove the version bundled with your JDK instead.
PS: GlassFish v3 is out, GlassFish v3 prelude is outdated, you should upgrade.
MikeD!
After many years, I am using NetBeans again. As I realized many features are included but others get "lost". I am planning to install several versions.
In NetBeans 6.7.1, to know what version of Java DB NetBeans is using, right click the Java DB node and ckeck the properties.
The path next to the label Java DB Installation tells you what installation is currently in use.
The path next to the label Database Location is used as the value for the property derby.system.home. This property tells Java DB where to create/find the individual databases folders. Besides, this folder holds two files called derby.properties and derby.log.
*derby.properties* establishes persistently system-wide properties.
Do not worry about duplicates. As you can see NetBeans uses 1 at a time. Nevertheless, as a recommendation, choose an installation and stick to it. During my tests I changed the path to the Java DB Installation several times and played with the user authentication properties inside derby.properties and eventually NetBeans could not create new databases in the regular way. So, I had to re-install NetBeans (I use the OS independent zip).
Regarding GlassFish, I have not experimented yet. But, it is reasonable to think that there is some limited set of options about using a different version of Java DB. For example, NetBeans 6.7.1 Java DB support fails if you set the netbeans_jdkhome property so that it points to a JDK version equal or higher than 1.7.0. That tells us something, right?
I will try to tell you anything useful I find out during my tests.
George