How to run a maven Java app on a server - java

I have a standalone application which I have deployed using the Maven release plugin.
I now need to run it on the remote server...
Would you recommend using the mvn exec plugin?
Otherwise whats the best way of running the app (i.e. working out the correct classpath etc).
Thxs

You can use the Maven Assembly Plugin with jar-with-dependencies descriptor (it's one of default descriptors). It should include all dependencies, allowing you to easily run the jar on the server.

Either the exec plugin, or use the dependencies plugin (or any of the jarjar-/onejar-type utilities) to create an all-in-one jar and just distribute that.

Related

Use build.gradle for deployment

I'm learning how to use gradle to build my java applications. Currently I'm using eclipse with buildship plugin. I have it building my JARs and WARs, and also have gradle running my JUnit and Selenium tests. I like that it pulls in the dependencies I need as I need them during development.
It seems like it would make sense if my build.gradle files define my dependencies to build and run my application in dev then I should be able to use them for deployment. Otherwise I have to retrieve all my dependencies by some other means and deploy to my production environment, and managing 2 different methods of retrieving and deploying dependencies seems to be a risk for problems.
Can I use gradle or at least my build.gradle files in some way for my deployment?
Take a look at the gradle distribution plugin. This plugin adds tasks to create an "install folder" or an archive file (zip or tar) containing all the dependencies you'll need to execute/deploy your application.
Gradle application plugin also generates shell/bat scripts to invoke your application.

appcfg.sh basics. how to compile servlets in command line?

does appcfg.sh compile servlets or olny deploy compiled project ? If it doesn't how can I compile whole project in the command line?
It's highly recommended to use an IDE to build Java web projects, especially GAE projects:
Eclipse with Google Plugin (free)
IDEA with GAE plugin (commercial)
If you dislike IDEs, then at least use maven with gae plugin.
You can do this by specifying the right dependencies in your master BUILD file:
The binary should depend on everything it needs to run.
You can create another target for deployment. That target should depend on the binary, and also on everything else needed to deploy it.
Google AppEngine supports Apache Ant for command-line builds. AppEngine Java SDK also includes Ant macros to run appcfg.sh tasks from Ant.

Using maven to produce production ready output

I have a muti-module maven project, and I created a new module that depends on 3 other modules. (I already have a web app maven module that produces a .war file, now I need this)
This module's output is a .jar, and it has a few resources also which are:
spring context xml file
properties file
Now I want to produce a production ready folder so I can upload it to my server. I am hoping maven can do this for me.
I need the following layout:
myjar.jar
/libs/ (the 3 other maven modules that are dependancies)
/resources
Also, there are some generic dependancies that my parent pom.xml have like slf4j/log4j/ that I also need to package.
It would be cool if I could add a switch to mvn that will produce this like:
mvn clean install production
I plan on running this on my server via the command line.
I think what you are looking for is a Maven Assembly:
https://maven.apache.org/plugins/maven-assembly-plugin/
You can use profiles to disable the generation of the assembly by default (can speed up the development process).
#puce is right in that you may be best to use the Assembly Plugin. What you can't do easily is add another lifecycle 'production' to maven. If you have time you could write a plugin to do this, but you might be better off using a profile called 'production' or 'prod-deploy' to enable the coping into place on the server.
mvn clean install -Pprod-deploy
One thing to remember with maven is that it is very good at building projects in using it's conventions, but it is pretty bad at actually script things to happen out side of the build lifecycle.
I have on several occasions used external scripting tools such as ant/python/bash and groovy to first run the build using mvn then to script the deployment in a more natural language.
The intention of Maven is building not deployment in the sense to production. For this purpose i would recommend things like Chef or Puppet. From a technial point of view it's of course possible to handle such things via Maven. What also possible to build on CI solution like Jenkins. Furthermore it's possible to run a script from Jenkins to do the deployment on production.

deploy java jar remotely during maven build

I have a small maven project that build a java jar file. I added a plugin (maven-antrun-plugin) in order to start it during maven's build phase. This also works in the build server (Continuum) which is good.
Now I would also like to copy the artifact jar to another server. What is the best way for doing that? I saw that you can make maven execute bash script, would that be a good way?
thanks!
It depends on your server and what options you have for uploading jars there. One of the options could be to use Maven Wagon plugin, which supports number of protocols, including ssh, ftp, webdaw.

How can I run a GWT app from gwt-maven-plugin without any browser plugins?

For a GWT application which I build with the GWT Maven Plugin (gwt-maven-plugin), I can run the GWT Development environment with
mvn compile war:exploded gwt:run
and then launch a browser. This requires that the browser provides the GWT Developer Plugin. (Firefox 6 for example does not yet support the GWT Plugin).
Does the GWT Maven Plugin also allow to simply run the included Jetty container with the GWT application, without a development mode?
After configuring gwt-maven plugin you could simply run the following.
mvn jetty:run-war
After gwt compilation the resulting war will be placed in jetty and started via Maven Jetty Plugin.
The only way to run the project without plugin is to compile it and run on a server. If you are using Netbeans just hit run. The IDE will compile and deploy project on a server. In other way just compile it with the following command (you can omit tests and reports):
mvn clean:clean resources:resources compiler:compile war:exploded resources:testResources compiler:testCompile surefire:test gwt:compile war:war
After this you 've got ready to deploy war file. To deploy it to the Glassfish there are now basically three options:
Maven GlassFish Plugin
A first option would be to use the Maven GlassFish Plugin. This plugin allows to interact with a local or remote GlassFish install and the management of Glassfish domains and component deployments from within the Maven build lifecycle.
Maven Embedded GlassFish Plugin
The second option would be to use the Maven Embedded Glassfish Plugin. As stated by its name, this plugin doesn't rely on an existing install but uses an embedded GlassFish, running in the same JVM as the plugin. This plugin is extremely nice if you want to keep your build portable (anybody can get your POM and run a build involving GlassFish without having it installed) with almost the same features as a normal GlassFish install, except clustering of course (you can use a preconfigured domain.xml if you want). See Testing with the GlassFish Maven plugin and JavaDB Embedded for an example.
Maven Cargo Plugin
The work initiated by Kohsuke Kawagushi as been finally integrated in Cargo and, starting with Cargo 1.0.1, GlassFish 3.x is now supported. Using the Maven Cargo plugin is thus a third option. This would be interesting for builds that want to interact with containers in an agnostic way. But I'm not sure Cargo allows all the flexibility of the GlassFish specific plugin(s) (e.g. deployment of JMS resources, etc).

Categories

Resources