I have a project with maven, this a multimodule project
Mainproject
project1 - jar
project2 - jar
project3 - web
Now that I finished the project I want to test it on the server but don't know how to upload them, on my computer I have added a plug for tomcat which deploys the war file to tomcat automatically, but the server doesn't have maven.
What is the way for moving to production with this kind of projects?
Should I just upload the target directories for each module?
Thanks
You're asking a few questions here. There is the "how do I test on a server" one, and there is "what is the way for moving to production" one. And they can be quite different.
I have assumed that the JAR files in the project are used by the WAR file and packaged within its WEB-INF/lib directory. If I'm wrong, that's cool. Just this sort of information is handy to know.
Maven is a build tool. It is not a deployment tool. What you have at the end of this, is a WAR file. If you run mvn install (or mvn deploy) you have a SNAPSHOT version of the WAR file. This would be suitable for quick, ad-hoc testing to other machines. But you would most likely use methods approriate for the hosting container for making them available. Note: a Maven DEPLOY is a different thing from a DEPLOY a war file to tomcat.
To my mind, if you're putting anything into production, or in front of a customer, or in front of a testing group, you should use Maven to make a Release of the product. That is, using the release plugin (via the release:prepare and release:plugin goals) to create a non-SNAPSHOT release of your artifact (in this case, a official version of the WAR file). Once you have that WAR file, you can migrate it to your production server in whatever way is easiest (copy, deploy into tomcat in the best way). You haven't mentioned if there are database requirements for this web application, and that would need to be considered before you change any production application.
But, once you have official versions, you have tags of source code, and you can accurately know what code is being run.
What I don't think you're going to get is being able to automatically copy the WAR file into a production server from your development environment. Here be dragons.
Related
I am new to jenkins so i don't know in depth about it. But in recent days we wanted to change from svn repository to GIT in which we have a java project created in dynamic web project. Now we have to deploy this project in jenkins. But i read that in jenkins only projects created in maven are accepted but not any other. Our project is a huge project and its created using dynamic web project. So if we want to convert to maven project will there be any code changes like many??
What are the jar files or any configuration files needed for the change??
I don't know whether this question is quite suitable to ask or not but we have less time and i am completely new to jenkins.Any suggestions or answers will be valuable to me
You will need to think about how you will run your application in production. Will you run it as a packaged war file in tomcat, jetty or another JEE server or will you run it using an embedded server (embedded tomcat etc) where the server is packaged with your application as an executable jar file.
Once you work that out you should think about how you are going to build the application, Maven, Gradle and Ant + Ivy are your three main options. Jenkins supports all of these options, not just maven. Besides being able to help you build your application in a standardized way, these tools will be able to help you manage your dependencies.
There really is not much configuration required once you know how to use the tools and your dependencies can be removed from your /lib folder (or wherever you are currently storing them) as a result.
So take some time to read up about each one, make your choice and then apply it to your project. It is a worthwhile investment and something you will use over an over again.
Jenkins makes a LOT of things easier if you have a Maven project, but you can specify a free form project where you can specify your own build command. This is not coupled with the git/svn repository.
Experiment with Jenkins. It is rather nice, and can do a lot of things when you learn it better.
I have a Java web project that uses Maven standard directory layout: java files gets into java (actually: /src/main/java), resources into resources, web content into webapp.
Then we wanted to improve our web layer, by adding bower, sass, gulp etc. Our gulp build compiles scss, minimize javascripts, optimize images etc, everything what you would expect. But this introduced 1) another build tool, gulp and 2) generated files by gulp.
Question is how to organize such project? One way could be:
(A) gulp builds into webapp folder
In this solution, all javascript,images,scss files are stored in /src/main/assets and gets build into the /src/main/webapp. Both sources and gulp-generated files gets committed to the git. The gradle build is independent from gulp, and it is ok for the users that does not have gulp installed - like those who needs to work only on backend. Also, CI servers does not depend on gulp stuff.
(B) use gulp from gradle during build
In this solution, gulp is called from gradle. Gradle therefore builds everything. And you must use gradle every time when you want to try something. Also, every developer needs to have gulp installed, what may be a problem for developers using windows (as i've been told). Also CI server should know how to run gulp.
My team is torn between these two options. Does anyone have any working experience with either of these solutions?
I'm currently using Java + Grunt + Maven. I've found there are two ways of packaging your frontend with your backend and the same will certainly apply to Gulp.
In the end it's up to what's best for your project/team. From my experience I usually use option B when working with others since the decoupling is easily worth the other issues. When I'm doing my own side projects I always go for option A because it's just easier to launch one webserver and to run a local environment closer to what DEV/PROD is like.
A) Put your frontend into the webapp folder (ex. https://github.com/kdubb1337/maven-grunt-webapp)
Benefits - You can launch your backend and do development all in one place and working with Spring security is a snap, even without OAUTH. Fewer issues working with two webservers up on your local environment when they would normally be bundled into one port on other environments.
B) Keep your frontend in a different folder, or even in a different repo that you clone into the root folder of your backend repo. (ex. https://github.com/kdubb1337/maven-grunt) see the 'yo' folder
Benefits - Fantastic decoupling so front end developers can live in joy without having to even install java locally or worry about recompiling your backend. Works great if you want Travis (or your favourite CI app) to do unit tests on the backend and the frontend.
EDIT I've found this awesome plugin you can use with maven/gradle to build the frontend https://github.com/eirslett/frontend-maven-plugin. Seems like the way to go, will be refactoring my starter projects with this guy for grunt and gulp
The current best practice here is to treat your frontend build as a separate project and put it in its own Maven or Gradle module. Have your Java build system invoke the JavaScript tooling (e.g., with the maven-exec-plugin) and save the output into the appropriate directory in target or build. Bundle up the results in a jar and serve off the classpath.
If you're using Bower, you only need the base Node install on your CI server, and your Java build can invoke the necessary build process from there, fetching JS packages as needed. Don't forget to (1) use --save and (2) exclude the JS modules directory from source control.
In addition, I suggest looking at RaveJS, which manages your JavaScript build and keeps you from having to configure watchers and such during development.
My recommended best practice is using the com.github.eirslett.frontend-maven-plugin (or the maven grunt plugin) to call the grunt/gulp build from mvn (in process resources goal). When CI builds, it's all integrated, even npm etc can be installed in mvn's target so you don't have bother to configure your CI server for npm.
When developers build, then mostly still just use one maven command. For JS/CSS/HTML developers, after mvn clean install, they can run grunt/gulp "watch" in the background to get their JS changes reflected immediately in the browser without incurring any maven overhead (just the wicked fast gulp/grunt tasks).
Deploy the UI components on default Tomcat webapp directory.
Deploy the class files on "wtpwebapps" (default directory for uploading war through eclipse) directory.
Setting Eclipse
Go to server tab, open properties for tomcat
(source: scotch.io)
Make sure, the location should be [workspace metadata]
Then double click on tomcat to open Tomcat overview.
(source: scotch.io)
Set server location to "Use tomcat location".
Grunt/Gulp Setting
Use the copy task to copy the build UI file to<tomcat installation directory>/webapps/<contextRoot>/
https://pub.scotch.io/#ankur841/eclipse-tomcat-deployment-with-gruntgulp-build
I have a Maven, Java project with Eclipse and Jboss 4. Currently, after doing clean, install goals I am moving EAR and WAR files into Jboss Deploy folder manually. But every time this process hard to do. Are there any plug-ins or tools to do this job? I tried the "org.codehaus.mojo" plug-in but it did't work. Are there any other goals in Maven to deploy automatically to Server from Eclipse?
For such purposes you can use cargo which is intended for functional tests but supports the deployment of artifacts like ear, war into appropriate container.
may maven-war-plugin can help you
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)
I will use Apache Ant and Apache Ivy to build a web application which is deployed to a local Tomcat instance (during development). I have some questions:
I want to grab most of my dependencies from the Maven2 repositories which works fine, but for the servlet JAR I would like to use the one Tomcat provides. Is there a way to do that using Ivy? And what do you think about doing so?
I download the Ivy JAR using Ant to "auto install" it into ~/.ivy2/jar/ivy.jar and I have the Ivy cache at its default location ~/.ivy2/cache . I keep both of these locations outside the project directory on purpose. Good idea?
Do you have an example of how to use Ant for the build file, Ivy to resolve dependencies, compile a WAR file and deploy it to a local (at the moment) Tomcat installation? I'm looking for something to have as a best practice which I then can modify further.
I've used some examples on the Ivy web site and modified them. Is there anything I should change? The build file can be seen at http://pastebin.com/f7b34abc2 , as I had problems pasting XML code in here.
(Please notice that I'm not looking for the suggestion that I should use Maven2, even if the suggestion is well intended.)
At runtime tomcat will use it's own away as it's classloader will exclude any jar with javax.servlet.Servlet in it. If you really really must compile against it you will have to do it in the ant script, and either copy it or reference it in the compile classpath.
On the other stuff, downloading ivy on demand is a good idea as it will prevent checking the ivy jar into the project scm repo as I have done in the past, whether you download it to the project directory or the user home is a matter of personal preference. The ivy cache on the other hand should be shared with other projects so the user home directory is a good location.
Building the war file isn't any different once you have done ivy:retrieve as the jar files required will be local to the project, just use the ant war task to create the war as normal. This is one advantage to ivy, that once the jars are downloaded it has no more to do in the build and you can just use ant to compile and package your project.
Had a quick look at your build file, looks perfectly sane.
Hope this helps.