How to deploy a java jar file to remote server through maven - java

I want to deploy a jar file to a remote server and run it. Is there a plugin for maven can do this process? I know that tomcat for maven plugin can deploy the war file to remote server, but my project is not a servlet project. I think the process is that:
1. transfer the jar file to remote server.
2. ran the jar file.
What is a better solution? Thanks!

A combination of these two questions will probably be what you need:
Maven copy local file to remote server using SSH
Run remote command via ssh using Maven3

Related

deploy jar file using Jenkins

How to deploy a jar file using Jenkins deployment jobs?
Is there any specific plugin available for jar deployments.
For War or EAR, we can go to Jenkins_deployment Jobs >> Post-build Actions >> Deploy war/ear to a container - and provide the below info.
WAR/EAR files,
Context path,
Containers
Can anyone please help in this?
Most containers have a directory where you can "place" the war, in order to deploy it.
Therefore in Jenkins you can set up Send build artifacts over SSH
Name: my_server123 (You must have a configured server)
Transfers: Transfer set:
source files: `path/to/target/*.war
remove prefix: `path/to/target
On configuring the server, you should go in Configure Jenkins -> Configure system -> SSH Servers
Add the server you need to deploy to, username (+password) and Remote directory: /opt/app/tomcat/webapps (or whatever)
If you want to send artifacts from windows build server to linux machine you can use send artifact over ssh from build section
If you want to send artifact from windows build server to windows application server you can use robocopy
Please have a look at the SCP plugin
This plugin uploads build artifacts to repository sites using SCP (SSH) protocol.

Maven or Ant for autodeploy and run project on remote server

I have a question according to automate my project lifecycle.
Now i do this manualy:
build my project with Ant, get target jar, rename it manualy (add
suffix, like version2.0-myProject.jar);
connect to remote server via ssh, open FreeComander and copy jar
file and INI-properties files to different folders on remote server;
Remoutly run my application throws putty (exec bat file on server,
which contain all cmd run command. This .bat contain plink.exe remote command to Lunux server, whoes contain instance of app).
What i want to do:
i want to automation deployment procces, include build phase and app run phase,
i want to do this:
When buld executed, user asked for output-jar file suffux(like varian2-myapp.jar), ask user for properties file with what programm will execute later, and ask user for Allocated memory for JVM (now it is part of cmd comand in .bat file)
My app is simple, contains 15 Classes and 3 external libs. I want to make deployment easy and automate this process, i learn that Maven or Ant Build can help me. Please say, what way is more comfort for my task of using this build systems.
With Maven you can use the Maven Release Plugin to deploy your package (which could be a zip with your jar and other dependencies for example) to a Maven repository (which you could be running in one of your server).
This page should get you started:
http://maven.apache.org/maven-release/maven-release-plugin/
With Ant, you can use Apache Ivy instead:
http://ant.apache.org/ivy/history/2.2.0/index.html
You then need a way to tell the server serving your app to pull the package and start using it (install it).
You could write a simple script that pulls the repo, which you trigger remotely, maybe using
plink -m
as you are doing now, or use one pre-built automation software, like https://puppet.com/.

How to copy Tomcat logs to Jenkins & display them after each deployment

I'm using Jenkins for building & deploying a Java app to Tomcat. I use the deployer plugin to deploy to my Tomcat container. However I have an additional requirement which is - after each deployment I should be able to view the Tomcat log in Jenkins. Is there a way to achieve this? Tomcat & Jenkins are running on different servers.
On *nix, you can use Execute Shell build step to scp files from remote machine back Jenkins's workspace
scp login#remote.server:/path/to/catalina.log ${WORKSPACE}/catalina.log
Once they are in Jenkins workspace, you can just cat them to the console log
cat ${WORKSPACE}/catalina.log
You could then further archive them as any other artifact from workspace

Deploying Spring MVC project

I've developed a small MVC project using Spring MVC, Hibernate, MySQL, Maven and Tomcat. I can run and test the application (locally) smoothly.
Now I need to publish/deploy this project on an (online) server that have only Tomcat installed on it. How can I publish/deploy the project online? Is there any special build I should do? What files I shall upload and to where?
There are several types of development options available.
For development on localhost EAR (Exploded ARchive) type of project is usually used (because you can easily make hot deploy on servery). But for production WAR (Web ARchive) is used (basically it's the same EAR archive, but compressed using ZIP algorithm).
If you want to deploy your project to remote Tomcat server then make your project as WAR archive and upload it to Tomcat's webapps directory. Then you might need to restart Tomcat. But it's manual way of deploying.
Better option is to use automated build tools (like Maven) which can compile your project, run unit tests, deploy on web server (local or remote) etc.
This one is a great example of how to deploy your project on Tomcat server by using Maven's tomcat-maven-plugin: http://www.mkyong.com/maven/how-to-deploy-maven-based-war-file-to-tomcat/
Good luck ;)
Do a mvn clean install and you will get a .war file in your target directory of web module.
Copy it and paste it in tomcat_home/webapps directory and restart tomcat. Thats it. now, you can access it in whatever configured port (eg: http://localhost:8080/<your webapp war name>). lets say your war name is myapp.war, then tomcat would have extracted it into myapp folder in webapps.
so your url will be http://localhost:8080/myapp
With maven deploy command, usually gets errors for various reasons.
if you work in Unix/Linux system, I recommend using "rsync" method on console. (You can write own shell script to manage easily). It helps not only deploying without a problem but also helps to get time while redeploying (only uploading changed / new files). Because maven deploy / redeploy uploads your project as a bundle in jar/war. However "rysnc" method uploads your project files one by one.
Before using it, you should sure that two conditions.
1- your project is built in target folder (Spring Tool Suite)
2- you have access to tomcat via ssh
example code : (v_ : prefix which is variable(customizable))
rsync -avz v_your_project_in_target root#v_ip:v_tomcat_name/webapps/v_project_name
(Second sharing)

Jar deployment in Netbeans - howto?

I've created Java app in Netbeans,
today I moved that app into Maven project,
I've created all dependencies in pom.xml, and application builds succesfuly and runs as before Maven migration.
However I have problem with deployment,
I was trying to use that Deployment of artifacts with FTP (Maven Deploy Plugin) but after inserting Netbeans project is broken.
My questions are:
What is easiest way to copy jar and maven files to some server by ftp or scp after pressing F6 in Netbeans (build button),
also how to run that app? before Maven I was using WinSCP to copy jar file, I've copied also lib directory with dependencies and I was using:
java -jar app.jar
Can Maven on remote host use java7 not system java?
I have jdk7u4 untarred on server, and I'm using that to run my application.
Can maven invoked by command line be handled by system java, but run application from java7 or I have to have only java7 in PATH?
Can Maven be bundled to single jar so I can run:
maven app.jar PARAM1 PARAM2..

Categories