How to transfer file to server using maven - java

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

Related

How to configure properties and deploy application from Jenkins to tomcat

Is it possible to deploy a war file from Jenkins to tomcat with an application properties configuration?
Instead of building the war file from any version controll, I want to give a war file directly to Jenkins for deployment. Before that, some application properites(e.g., db connection, third-party services URL) will need to be configured according to the original deployed app and then deployed to tomcat. This might need to be done by writing some script?
For example, the deployed app is version 1.0 and db connection properties is port 5433. The war file which I gave is version 1.1 and the db port default is 5432. So, I have to update the properties in the war to 5433 for db port and deploy to tomcat to get a version 1.1 app and with correct db connectino settings(5433)
Does there have any plugin of Jenkins can achieve this?
Yes, you can do this through the scripts.
In the Build section of the Jenkins there is an option called Execute Shell - there you can do these things
1) Execute the script - which updates properties
sh script_with_changes.sh
2) Copy the war file as shown below using rsync command
rsync -avz /path/where/war/exists/xxx.war username#machineip:/tomcat/path/to/copy/xxx.war

Deploying Java application on remote server using Maven

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.

autodeploy web service java with glassfish server 4.1.1?

How can I do to deploy the web service automatically,I have the webService.war file ?I'm working with glassfish 4.1.1 and use a external library postgresql-9.4-1203.jdbc4.jar and I dont know how deploy the .war file thanks.
Not sure what you mean by deploy automatically, however, DeshanR's suggestion is still workable even for 4.1.1. You also have two other options:
You can deploy the war file from the browser by pointing your browser to yourdomain:4848. This will bring you to the glassfish admin console (provided glassfish is up and running and your glassfish is set to use port 4848, which by default it should be). You can then deploy your war file under the applications menu.
If this is a dev environment you can also deploy to your local glassfish from your IDE. This is an example for Eclipse. Connecting your IDE to your local glassfish has the advantage of allowing you to publish changes as you make them.
If you're using the postgres jar file for the JDBC driver and Glassfish's Connection Pool, you will need to restart the server to deploy that file after copying it in to your domain/ext/lib directory.
For the WAR, there is the asadmin command line client, your IDE may have direct support to deploy it from there, you can use the GF administration console, or you can copy the WAR in to the domain/autodeploy directory (assuming you have autodeploy enabled, which is it by default).
There are also HTTP and JMX interfaces, but those are probably not what you're looking for.

maven deployment of configuration information to tomcat

In my current development/deployment workflow I deploy my (Java/Spring) web apps to a remote tomcat containers by using the tomcat7 maven plugin.
This makes easy for me to simply deploy the new version of my app by invoking
mvn tomcat7:deploy
My specific problem now is how to correctly handle configuration information: at the moment I keep configuration information (db connection info, passwords, etc.) in .properties files which are packaged with my war and then deployed remotely to the container as described above. An improvement of this process is the use of maven profiles to include different versions of .properties for different target deploy environments.
The problem with this approach is that sentitive information (eg. passwords) are packaged with the war file, while I would prefer to have them somewhere else on the server, visible to the web app (e.g. as part of its classpath), but manageable independently (so as to allow a change in some config settings withouth having to rebuild/redeploy the app).
The only solution I've found so far for this implies the following steps:
1) do not include the .properties in the packaged war
2) deploy the war to the remote server with mvn tomcat7:deploy
3) manually copy the .properties on some server folders where they are accessible from the web app via classpath
In step 3) "manually" means not using maven-based mechanisms for this step. Can someone suggest me some mechanism through which both the packaged war and the configuration files can be separately deployed to a remote server (for instance some ?
For example , you can do this :
1. Create module_config.zip with maven-assembly-plugin contains : *.properties
2. Deploy war with mvn tomcat7:deploy
3. Start script to copy module_config > dir_deploy_application
4. ReStart tomcat7
You can do it with (sh script) or (jenkins)

How to export war with different file version to different deployment destination

I am use myeclipse to develop tomcat web application.
When I finish developing and decide to export war file to upload to remote server, I always have to change the configuration file like hiberante.cfg.xml, to connect to different mysql server.
Is there any way, like maven plugin or something that could keep two copy a resource like the hiberante configuration file. So when i export war I could choose like by profile or anything like that to include different version of a/some resources?
Appriciated.
That's usually the job of your config manager (Chef, Ansible, etc.) or at least the job of your source management tool (Git, SVN, etc.) to choose/contain the right config.
My quick way of deploying using Git is to have a git production branch that contains one extra commit (that is config changes); and for deploy I would just rebase the production branch from the working branch and deploy.

Categories

Resources