Moving web application (Java/JSP) to a web server - java

I have developed an application with Netbeans (Using Java, JSP and JQuery) in Windows environment. Now I am ready to transfer the application to a web host so that the application can be available on the Web and I am told that the application would have to be moved to a linux environment (hosting service already bought). Here are my concerns:
How to convert my code to Linux? Is there an automatic tool for this?
How to deploy my application to the server online (what do I need to copy and to what directory on the web?)
My application writes to a directory on c:drive on my laptop, what should I do to make the application write to correct directory a designated directory on the web server?
I have read here and there online but just haven't got specific solutions to this.

How to convert my code to Linux? Is there an automatic tool for this?
One of the Java key features is portability, so as far as you haven't used any OS-specific code like running a program using CMD or similar or a library that is OS-dependant (which is rare in these times but there are some yet), then you don't have anything to do.
How to deploy my application to the server online (what do I need to copy and to what directory on the web?)
You need to generate a WAR file. This file will zip all your web pages (JSPs) and web resources (js, css, image files) along with the Java binaries (*.class) and libraries (that must be on WEB-INF/lib folder).
Since you're working with NetBeans, here's a Q/A to generate the war file: How can I create a war file of my project in NetBeans?
This war file must be placed in the deploy folder of your web application server. Usually, the hosting provides you the tools (generally a link on the web with user and password) to administrate the host, based on this you should ask (or find it by yourself) the option to upload the war file.
My application writes to a directory on c:drive on my laptop, what should I do to make the application write to correct directory a designated directory on the web server?
You need to configure this path as a constant in your application, or even better, configure it in a properties file (or somewhere else) in order to be read and use it by your application easily. Remember that the path should be generic to be supported in almost every OS. For example, if you use a path with name
C:\some\path\for\files
Its generic form will be:
/some/path/for/files
Since you're going to work on Linux, make sure the user who executes the Tomcat (or the web application server you will use on production) have enough permissions to write on that folder. This can be easily done (and somebody here can fix this please) using the chown command:
#> chown -R user /some/path/for/files
Here's another Q/A to manage files and path on Java web applications: How to provide relative path in File class to upload any file?

OK, first a few thoughts:
Convert code to Linux. Once you have your ear of war file, you can just deploy them. It's best if you use UTF8 enconding in your files, specially if you use special characters, but that would be an issue you could test out when you deploy, could also be dependant on the Linux configuration. Having that said, Java is portable and you only have to be sure that the archive you create is compatible with the AppServer that's installed on the Linux hosting. You should get all the information you need about the deployment environment from the hosting site / company.
Deployment will depend from site to site, they should give you all instructions.
Here you might have a problem. I would say that the easiest way is to just map the directory in a properties file and customize it on every machine you use it. That's the easy part so far. However, you should check if your site will give you access to a directory, and be aware of space limitations and cleanup of the files. If you get, let's say, 100MB and you use 10MB a day, you might end up with trouble after 10 days...

Related

Migration of Java Applets to Java WebStart and GWT

I have an application that uses a "signed" applet which is packaged inside a jar that does the following things:
Checks whether the file exists in the directory while uploading a file and opens a form for details.
An applet is included in JSP and checks the file exists in local system by getting storage path while uploading.
Checks whether the applet is active and downloads the file to local system.
Add files to application that will be stored as local copy in file system.
As the support for applets is getting removed, I would want to migrate from applets. I would like to know is Java Web Start the best option for replacing applets in terms of "security, trusted code" and signature. Are there any other technologies that comes useful for my application in the above areas?
Also found that
Migrate Java Applet to what/where?
Replace Applet in downloading and executing a file
Any suggestions on this?

The easy and modern way to manage the changes of a java project on a deployment server

This is i am writing doubting that whether the method i am using outdated or not. I have a java webserver and usually i will have changes on and when i need to upload the changes i will build the project locally and upload java files and restart.
The other method is upload war file completely and place into webapps folder. In this case if there is any dynamic images or files uploaded by users, i need to take a backup and replaced with the newly created folder after the war file deployment.
Is the both above are good method or anybody can suggest me an even more good method to manage my live environment changes.

Packaging a Java app. w/DB to run on client machine

I made a simple java desktop application using embedded database. I wanted to package all files into a single file like exe so that client can click just on one file and use the application. I made the jar file and its working fine on my system when double clicking. I wanted to package the DB file along with jar because the data is shown only when the DB file is in the same folder of jar file.
I came across several tools like launch4j, install4j etc. but I didn't find where to include the DB file along with the package.
It sounds like you want an installer of some description, such as IzPack. This would allow you to package both jar and database together, and install them on a client system.
A good way to deploy rich client (e.g. Swing/AWT) apps. that require some set-up (as in, installing a DB) is by using Java Web Start.
JWS offers the ExtensionInstallerService which..
..is used by an extension installer to communicate with the JNLP Client. It provides the following type of functionality:
Access to prefered installation location, and other information about the JNLP Client
Manipulation of the JNLP Client's download screen
Methods for updating the JNLP Client with the installed code
Here is a demo. of the EIS (with code, build file etc.).

Servlet : What exactly the use of context.getRealPath(" ");

As i know it returns the application path? But what exactly the use of it.
In many environments the application user is not allowed to read any files outside of the deployment directory. This is mostly done for security purposes - for example if someone hacks your application they won't be able to read a passwords file.
And in professionally managed environments developers often don't have a say in which directory the application will be placed.
So if you need to read a file like properties, images, certificates, etc. you can place it in the application directory (or .war file) and use getRealPath("") to get the path you need to load.
As an alternative you can place the external files on the classpath but there are sometimes issues with this. For large files most app servers will try to load the entire file into memory and cache it if it is on the classpath.
The getRealPath() gives the absolute path (on the file system) leading to a file specified in the parameters of the call. It returns the path in the format specific to the OS.
The getContextPath() on the other hand returns the URI or the relative path to the resource.
As far as I remember, I've used it to save images or other data files, since it allows you to see where your application is deployed at the moment. For example, Eclipse and Tomcat will create a temporary folder that's buried deep somewhere within your Eclipse profile and deploy the app there.
This is a real path in file system.
From javadoc:
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).
I think it is very clear. Why do we need this? Sometimes web applications perform some manipulation in file system. For example read stuff from files, write files etc. This API allows you to access the place where your JSPs and other stuff is really stored.

Is it possible to embed a jar file inside a flex application?

I have a great idea and I want to build a flex application around a .jar file. Is there a way I can go by embedding a jar file into the flex application?
There are ways to embed assets into a Flex application, however most people use this for images or other visual assets. I do not believe that jar is supported. Java and ActionScript are very different and you wouldn't be able to load a jar inside the flash player and execute it as a program or run commands against it.
If this is an AIR application, you may be able to do something using NativeProcess. But, such an approach is not the same as embedding a jar file in a Flex Application. It is taking your file and wrapping it up in an AIR installer and then communicating with that file as it runs natively on the machine.

Categories