8

I have developed a server [server.jar], and it is now working well (on my localhost). Now I want to "put" this server.jar on my remote server (ie: 122.152.12.33) and run it there, so My client application Replace "Localhost" with this ip and connect the [server.jar]...

How may I do that?

I found answers but didn't understand them (WAR? , and some configurations).

I am using NetBeans IDE. Deployment of Jar file and converting to war using netbeans.

Note I also use Mysql Database that I must upload it on the server side.

*Update: Another related Question:

If I want to try my server.jar on an existing website (Wordpress released site), just by adding my project in a folder, may this harm the online site?

And may I use php to run the Jar? (the site that is online is Link. I want to a create a folder http://akhbarna.com/MyPrject/ ... and then put the Jar there and run it by Php. Is it possible? And how this may effect the Online site?

HBon
  • 3
  • 3
EsmaeelQash
  • 480
  • 2
  • 6
  • 19

2 Answers2

16

Running in your IDE is a long way from released and working ;-)

Your question is quite general, so my answer is quite general too but covers the basic approach.

The key to this is thinking what would be needed to run a hello world application on a brand new desktop PC - you'd need to install Java, create a folder to contain your application and some scripts that run the program then copy your jar to the new desktop PC and run those scripts. It's no different on the server, only you'll probably be using 3rd party libraries and will probably install more than just Java.

Before we get to some more details, first off, the terms in the build, release and deployment space tend to be horribly overloaded. To clarify, in the following answer I mean the following:

  • artifact - the jar, war, zip, package, etc produced by a project.
  • release - building your code to create an artifact and deploying it.
  • deploy - uploading an artifact to a repository.
  • install - taking an artifact from a repository and putting on a server so that it can be run.

I'll assume you're starting from scratch and are working in a professional environment.

First thing to do is prepare your server. Like you did with your desktop, you're going to need to install some software - at a bare minimum Java and MySQL plus a Servlet container such as Tomcat if you're building a web-app. You've got two options, either you do these installations manually or use a tool like Puppet to automate them - I'd recommend the later because once setup you can build a server in minutes rather than days.

Then you're going to need some sort of build process that's separate from your IDE. Current popular tools for this are Maven or Gradle. The aim of the build is to produce an artifact containing everything that must be added to the server for your application to be installed. In the case of a stand-alone application this could be a zip with want amounts to a disk image in it (the jar(s), configuration, start/stop scripts) or in the case of a web-app a war, which is the standard deployment structure for a web-app.

Next you're going to need some sort of release process for your application and database scripts. I'm most familiar with Maven that is capable of creating jars, wars, propriatary zips or packages and which, with the use of its Release Plugin, performs all the updates, VCS tagging and deployment (into a repository such as Nexus) needed to perform a release. The database is a bit more tricky and is normally dictated by the DBAs who will apply the database changes - typically you end up with the scripts needed to create and modify the database plus a master script that runs those scripts in the correct order. Pop those in a zip and into the repository for safe keeping too.

Once you've released, you need some way to take the artifacts from the repository and install them onto the server. Obviously this can be done manually or with scripts but again I'd recommend using Puppet, at least for the artifacts targetted at the server. With the database scripts, while this can be automated too, it's more common to connect to the database and apply the scripts manually using a database console (don't forget to take backup of both code and database prior to installing a new version).

Finally you can start your system.

Nick Holt
  • 31,429
  • 4
  • 46
  • 56
  • 1
    Another related Q. , if I want to try my server.jar On an existing website (Wordpress released site), Just by adding my project in a folder. may this harm the online site? and may I use php to run the Jat ? (the site that is online is [Link](http://akhbarna.com/ar/), I want to create Folder http://akhbarna.com/MyPrject/ ... then put the Jar there and run it by Php, is it possible? and how this may effect the Online site? – EsmaeelQash Jan 18 '14 at 09:23
  • 1
    Given you'd be running your server.jar in a separate JVM from whatever else is running on your server the only effect it should have is to consume some of the servers resources, which may or may not be a problem depending how loaded the server currently is. Without knowing what you server is doing or what loaded it might expect it's impossible to say - best to ask another question including as many details as you can. – Nick Holt Jan 18 '14 at 16:27
2

First you need to install the database in the server (accesing by ssh)

Then you need to copy the jar on the server (sftp, scp...) and install a JVM on it (if there isn't installed yet -> you can check it executing java -v)

After that, like Brierson says, you need to run your jar (java -jar server.jar).

It's possible you need to add some libraries needed by the jar (define the classpath, explained here)

If your jar is a server then when executed probably it will bind to a port (for example, port 8080). To connect to your app in the remote server, you need to address your client to 122.152.12.33:8080 (IP:port)

Your server may have a firewall, so maybe you need to open the port (8080) of your server application.

Community
  • 1
  • 1
dbermudez
  • 562
  • 3
  • 9
  • The problem is the thread "java -jar server.jar" will be terminated while you lost connect with server'. – Albert.Qing Oct 31 '14 at 05:40
  • Albert, if this is the problem you can start your server process with a nohup command or using screens, as stated in http://stackoverflow.com/questions/4797050/how-to-run-process-as-background-and-never-die. If you are running in a windows environment, start the process as a service, as stated in http://stackoverflow.com/questions/1617458/how-to-create-windows-service-from-java-jar – dbermudez Nov 03 '14 at 16:50