简体   繁体   中英

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

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:

  1. 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.
  2. Deployment will depend from site to site, they should give you all instructions.
  3. 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM