Porting Java/Mysql application from Linux to Windows - java

I have written an application in Java and used MySQL as the database system. The user can insert or delete the rows in database tables. I have developed the application on Ubuntu 11.10 and it is working properly.
My question is how should I port this application to a Windows machine? Do I need to install MySQL server on that machine? If yes, how to pack all executables into a single .EXE. How do I make this application work on all platforms?

Java applications, unless you did some less ordinary things such as relying on line ending or did JNI, should generally work OOB in all the platforms java is supported. Test and fix the things that don't work.
MySQL installations are different per environment, and yes, you'd need the DB server on that environment too, if you plan to run it locally. Usually, you'd request the user to install MySQL and configure it to your application - I see a potential EULA/TOS issue with packaging MySQL binaries with your own application. If you'd do it anyway, you'd want to use an installer to create an install file for you that would include the files and perform steps that are needed.
Edit: see this thread for more convenient alternatives than using MySQL with your software and also for a note about the potential license agreement issue.

Related

How to make a server for a Java and MySQL application

I created a Java application that accesses a MySQL database (made using MySQL Workbench). I want to create an installer for my application so that other users can use it on other computers, but I can't figure out how to do so.
I tried using Launch4j and Inno Setup Compiler, but when I tried to install the application on another computer it didn't access my database.
After a bit of research, I found out that I (maybe?) have to use a server for my database, but I couldn't figure out what and how to do that.
My questions are:
Do I have to use a server to make my application installable on other computers?
What is the easiest server to use for this task?
PS: I'm very new at programming so please be as explicit as you can :)

Distributing java web applications

We have a java application hosted on JBoss with a Posgres DB, and we've traditionally been selling it as an appliance (full server with application installed). Now, we need to allow clients to be able to download and install it on their servers. What is the best way to approach this? Ideally, I'd like it to be a one packaged installation file that they can run and it checks for dependencies, deploys the war file, executes the postgres sql to setup the database and start up jboss.
JBoss and Postgres will be installed by the client prior to installation.
The simplest way is to use a bash script for Linux and possible bat/cmd files for Windows, though that is not ideal. Are there any libraries available to accomplish something like this?
install4j can be used to let users install applications. The installation package will contain everything needed (application, JBoss, postgres). Furthermore, it has ant and maven tasks, too, and you can even allow the users to do some basic configuration on-the-fly.
The latest version of JBoss is OSGi based. Have you consider to use this solution ?
If JBoss and Postgres are already preinstalled and configured by users as they wish then it would be very difficult to make a silver-bullet automatic installer that takes into account and correctly handles whatever incompatibilities it can face in real life.
Maybe a detailed install instruction would be enough. Especially for advanced users. For the others - bundle some diagnoctic scripts in case they face problem.
Also consider using liquibase to do automatic database initialization and migration on application's startup. This would greatly simplify the rest of install procedure: just check deps, make datasource and deploy app.

Creating an installer for Java program with database

Recently I made an application in using Swing, AWT and JDBC that manages some database. I used PostgreSQL as the backend with JDBC drivers to connect to the database. What I want to do is create a setup/installer program so that the application can be installed and used on any pc. My problem is I dont know how to integrate the database along?
Any help would be appreciated.
Take a lesson from most commercial applications that have a database component. Usually they require that the database be installed/configured beforehand and provide db scripts for their supported vendors. There are a lot of reasons for this. Most of these are related to the fact that organization's like to manage their own databases. This is often because they have company restrictions regarding security, maintenance, etc. Also a single database process may be shared between many different programs(if you install two instances of your application do you want to have to two installations of the database?).
Most folks(especially network admins) wouldn't want an application that ran around installing rogue DMBS's on their machine.
I wouldn't spend a ton of time attempting to install the database during your install process. Why re-invent the wheel when the vendor has already created an installation process for you? Instead install the database ahead of time and focus your installer instead on running the necessary scripts such that your application can connect to it on the first start up. What it does means is having your installer have the necessary drivers, connection information, and credentials to communicate with the database to get it initialized. After the DB is initialized then you can have additional routines that configure your application install such that it points to the database you initialized during the install. Taking this approach will not only be easier, but it will allow your application to do more interesting things like connect to remote databases or skip database initialization all together and connect to an existing database.
Writing an installer that also manages DB installation is a project in and of itself. The big question is do you need to install PostgreSQL from scratch or will you tell the user to install it themselves first?
I have attempted to do something similar and what I eventually did was build an installer with NSIS that includes Postgres and a JRE in the install bundle along with my program. The installer copies everything to the user's install location and creates all the required config files.
The biggest issue I had was that I had a number of config options to present to the user that would have taken a lot of programming in NSIS. So, I modified the ANT build scripts I already had written to build the project. What NSIS does then is copy the JRE to a temp location and start a Java installer GUI I wrote instead that gathers up all the config info and launches ANT in the background.
If you don't have much to configure or what you need to configure doesn't have many options, then you can probably do everything in NSIS directly. But, keep in mind that you need to be security conscious too. How are you creating a new user to run Postgres? What about directory permissions for you install? Who can start and stop the DB, who can read the db files, etc?
Maybe you may try a pure java database, like hsql, or h2, or derby....

Create an installer in Java

I want to create an installer using Java that install at first MySQL. The user tape at first the password of root user. Then the installer copy jar file into program files and create shortcut on desktop.
So my question how to install MySQL automatic via Java. Is there any way??
Thanks in advance.
best regards,
Ali
Depends on the platforms you want to install onto. Basically if you know how to do it via the command line, then you can write a shell script that is executed from Java, or a series of command line statements that are executed from Java to do it.
Since you mention root user, I'm guessing some flavor of linux? Doesn't MySQL already have ways of doing this that come with the installers and/or binary distributions?
This write-up might help you in creating a java installer: Convert Java to EXE (also has information about other platforms)
But, before going for that, I would like to ask you, why do you want o bundle MySQL with your java app? The recommended way, if you want a DBMS bundled in your app can be:
Ask the user the install MySQL him self. You app will use it.
Use SqLite (embedded RDBMS). Or even simpler, Berkley DB for a Key-value store. This approach will be super light and no installation needed.
You can try to perform a 'private' ad-hoc MySQL installation that is only used by your application: that means you will have to copy the binaries (please note they are different for each platform) plus some custom configuration files to a 'mysql' subdirectory of your programs' main directory.
I can assure you it won't be easy and fast to do. You have to struggle a bit making it work under each platform. This kind of stuff is always a bit tricky.
If you prefer to install MySQL in a system-wide manner (as a service, using the provided install package) you'll have to embed the package into your setup program and then use the proper operating system commands to install it. That would be different on each platform, and under Linux you'll have to install the proper package for each distro. Messy.
You can look at some commercial solutions for making Java install programs. See install4j for example.
Shipping MySQL with your Java application is not so easy. Are you sure you need MySQL, and you cannot use some simpler alternatives, like sqlite? If you choose sqlite, there are some 100% java solutions, and that means no difference between platforms and easy deploy of your application.
Think about it, listening to this simple advice can make you save 14-15 hours of work and debugging (with always some possibility of failure, because complex installers do fail).

Recommendations for Test Linux/Web Server Environment using Java

I'm a .NET developer looking do some research on my own time to better familiarize myself with Linux and Java (e.g JSP and Servlets).
My plan is to install Linux on an old PC. Then, install and configure a web server capable of hosting JavaServer Pages and Servlets. I would like to create a small web site with dynamic content being pulled from a database. Again, this site is only intended to be used by me for research and testing.
I have very little experience with Linux and Java. Did a couple projects back in college, but that was over 8 years ago.
Below are the questions I have about configuring a test environment I can use for research and testing.
1) What version of Linux should I install on my old PC?
2) What web server should I install on my Linux machine that can be used to host JavaServer Pages and Servlets?
3) What database should I install on the Linux machine? Since I'm doing this for research, it would be nice to test with a DBMS that is commonly used in the real world.
Thanks,
Chris.
You can use Debian, Tomcat and MySQL.
Debian is a fairly common linux distribution and will work on almost every PC.
Tomcat is a simple servlet container. It's the best choice if the only thing you want to do is servlets and JSP.
MySQL is, well MySQL :)
If you do mind using Linux, you can use Ubuntu which is more user-friendly but not really recommended as a server (at least for the default version).
These applications/distributions are from the most used and with the most active communities.
Resources :
debian.org
tomcat.apache.org
mysql.com
ubuntu.com
Whichever you want :-) At work, for example, our Linux servers run Red Hat Enterprise Linux, which is loosely based on Fedora, so that might be a good distribution to use that might be similar to what you would experience in the 'real world'.
Tomcat or JBoss Application Server would be good app servers to start with. Tomcat is just a servlet container, whereas JBoss supports more of the Java EE technologies. That said, many organisations find that a 'lightweight' app server like Tomcat is perfectly adequate.
MySQL and PostgreSQL are both widely-used open source database servers.
I would install the latest Ubuntu. The most user friendly and should work on your old PC.
I would install Glassfish or JBoss. Glassfish comes with Oracle's Java EE and is the easiest to install. JBoss is more widely used in commercial settings. Better yet, install both and try it on both!
MySQL is easy to install on Linux machines. In fact it's usually installed by default by the distribution.
Good luck! Linux is a great learning experience and a lot of fun!
I'm not a specialist in linux distributions, but as webserver the apache tomcat would be the best choice, I think version 6. The database may be a mysql, but for professional usage with more functionality postgresql will be the best choice.
Slackware. You will get lots of different answers on what distribution to use, and a lot of it is personal preference. I always prefer Slackware for server installations, and install all my software from source. I think of Ubuntu and Redhat more as client/desktop installations. I don't like to rely on packages to keep my servers up-to-date.
Tomcat. You don't need J2EE. Tomcat will do the job nicely.
MySQL. It's quite standard and works well.
1) As you want, but I suggest you a Red-Hat (CentOs for example) or Debian (Ubuntu for example) based distribution. With respectively Yum/RPMs and Aptitude/Synaptic, it will be easier to install Java (even if it is not difficult on other distributions).
2) To serve JSP pages and execute servlets, I suggest you Tomcat. It is much easier to install/configure it than other webservers (JBoss, Websphere, Weblogic, etc.), and you won't need them in a first time (EJB, etc.)
3) As a database, you can use MySQL (very easy to install), or PostgreSQL, or Oracle Express Edition (not Open Source but Free... And Oracle is very often used on big projects). From a Java point of view, it will be very similar (JDBC/Hibernate access to database "hide" the specificity of DB)
I think you are starting in the wrong place.
1.
If you want to try out linux try out linux. You don't need to install it - just download a "live CD". I believe the latest Ubuntu installer comes on a live cd.
2.
If you want to try out java web development you don't need to set up a server just install eclipse for java ee and create a dynamic web project. Then just start developing. Try to find some tutorials, etc. Eclipse can even download a development tomcat from within the ide.
3.
For databases - why not just use the same database you use with .net? I am sure there will be a jdbc driver and the code you write shouldn't be that different from any other database.

Categories

Resources