Deploying Java application on remote server using Maven - java

I am writing a Java application using Maven. I have to deploy the application on a remote powerful server to run experiments. The simplest way I figured out to do this was to build a jar-with-dependencies using Maven shading plugin and then copy the uber-jar to the remote server. However the jar is big, 100+ MB, and it takes some time to send it through our network. This is redundant because most of the jar consist of heavy dependencies (Scala, Spark, Jetty) and only a tiny portion of it changes when we change our code.
Can I use Maven to install the dependencies on the remote server and then only send the much smaller jar with no dependencies to the server?
I have SSH connection to the server and I can use the SCP plugin.

You mention Jetty in your question so I am assuming your application server is Jetty. I would try and upload the common library jars to the server and then including them in the jetty class path. This will be a one time task. Maybe this will help: How do I place jars in jetty/lib on the jetty classpath?.
After this you can use maven to built a "thin" war/jar which you can upload and deploy.

Related

Deploy Java application with Rest web services in Openshift server

I´m trying to deploy java application in OpenShift server. My application is divided in four projects: BBDD, Bussiness, Web Services and Web. When I create the application with openshift, it´s created this structure: src(this one has java, resources and webapp folders), webapps and pom.xml. I don´t know how to organize my projects into that structure to upload to the server.
I have put my web structure on webapp folder inside src. Then, I put the other projects on java folder. When I executed the application I can see my web pages and I can navigate for all of them but, when I call to a webservice I have the following error:
Http/1.1 404 not found
Thanks in advance,
Iban
Openshift is expecting to compile the application on their server using the pom.xml then run the application it built. To do that your project needs to be a maven webapplication project. Only when you have tested it locally would you expect that committing the code to your openshift server (using git) would it be able to compile and run the app successfully.
This means that you should not be uploading files using an SCP upload tool; you should be committing your source using git to your openshift server for it to compile then run your app.
The way I typically work with maven and openshift is to add a fragment of xml into the pom.xml to enable the jetty-maven-plugin to be able to use mvn jetty:run to build and launch the project to test it locally. If-and-only-if it works locally do I try to deploy it. That command is 'zero install' as maven downloads the jetty jars and runs them over your project.
Redhat openshift tends to promote redhat jboss AS application server as a Java solution so if you go down that route you should try mvn packageto make the war file and test it against a local jboss install before expecting it to work on the server. There is an approach where rather than committing code for the server to build and run you can build an EAR file locally and have that pushed to the server.
At the bottom of this answer I have a link to a demo I wrote which shows my preferred approach. I create my apps as a DIY cartridge which is an empty shell then customise the scripts in the .openshift folder to start the Java server of my choice. I use maven to build my webapp which I run using the jetty-maven-plugin to debug locally in Eclipse (maven IDE plugin lets me "debug as... > maven > "jetty:run"). Then I configure the pom.xml to build my whole app plus the jetty Java webserver into one huge runnable jar. Then I edit the start script to use "java -jar" to run my full app.
If you are using a DYI cartridge you don't need to use maven; I have used sbt as the build tool to create a runnable jar. You simply have to modify the scripts in the .openshift folder to download and run the tools you choose.
The demo I made GitHub at the link below has instructions on how to deploy it on openshift. So you may want to get that running then after you can both debug it locally and push it to your openshift server then rip out my code and add in all yours:
https://github.com/simbo1905/zkmongomaps

Build failure trying to add new jars to maven project on the server

I have a Jsf 1.2 maven application. I try to send automatic-report emails to users regarding the application daily usage. I add the required Jar files in my local project workspace and it works fine. I can send the email without any problem. However, when deploying the project war to server machine, the new jar files are not seen by the tomcat web-server. Although I add all the dependencies in pom.xml. What would the problem If the project works in local machine and does not work in remote server?

Runtime dependencies for GAE web app

After downloading the GAE SDK (1.7.1) I have a massive amount of JARs under my ${GAE_HOME}/lib/ directory:
I am in the process of setting up a build for my GAE web app on my local machine but also plan on setting up a QA machine. I'm also using an Ivy repository hosted on a 3rd server for resolving all of my web app's dependencies.
I need to know which GAE JARs I will need to package under my web app's WEB-INF/lib directory, and which ones are available to my web app at runtime on both the dev appserver as well as my live/production GAE servers.
So I ask: does the production environment of GAE make all these JARs available at runtime, or do I need to package them in my WAR? And do production GAE servers make the same dependencies available as the dev appserver, or do I need to have different dependency configurations for dev and production environments? Thanks in advance!
Please note: I am using the Google-Eclipse plugin for a few features, but not building or uploading/deployment. I'm setting up an external Ant build that calls Ivy and other tasks that I am running from a terminal. So I'm not interested in any build-related features of the plugin!

How to transfer file to server using maven

Once maven creates a WAR file (with mvn package) I would like to somehow transfer the war file onto another server and then execute a command on the server to deploy the war to tomcat. I am connected to the destination Windows 2008 Server via VPN. I can also ping the destination server while vpn'd in from my local machine.
Is there a way to do this transfer of the war from my local computer to windows 2008 server? Would I need to install something additionally on the windows server?
This blog entry details how to use the Maven Tomcat plugin to do this.
Issue “mvn tomcat:deploy” to package your project in a WAR file, and
deploy it to Tomcat server. To verify it, just access to the Tomcat’s
manager page and make sure “/mkyongWebApp” path is existed.
Basically you configure Tomcat to accept a remote deployment, configure your settings.xml with your Tomcat credentials, and set up the Tomcat Maven plugin with the hostname/port etc of your Tomcat server (phew!)
There are many ways, but none of them are ideal. I would personally discourage the use of Maven as a deployment or "devops" tool. If you really need to do this there's a good chance that your requirements are going to evolve and become more complicated as your application develops. Why not just start with CFEngine, Chef, Puppet, or other tools?
Warning aside, you could do the following:
Deploy with scp - The Maven Deploy Plugin can scp a file to a server. This overrides the real purpose of a deployment in Maven, but it will work. (Again the downside here is that you'll be overriding the real way that Maven was designed to work) For this to work you may need to explicitly add the SCP wagon provider, it used to be present by default, but it was removed.
Use Cargo to manipulate whatever server you use - http://cargo.codehaus.org/Maven2+plugin

Maven dump file on ftp server when deploying

My Maven builds a ready zipped package that just has to be uploaded to a ftp server.
Is there a plugin for this task? It should start when I choose the deploy goal.
I see some ftp support for the real way Maven deploys files, but nothing for a custom ftp upload.
What do you mean by a "custom" upload?
The deploy plugin doco describes how to normally deploy a build artifact using ftp.

Categories

Resources