Maven push only jsp without recompiling - java

This is my first time using maven on a project. Basically, I am working in the src on a webapp and when I am ready to push a change to the target i do a mvn clean install (this was what I was told to do).
The issue is that if I am just making a minor html tweak in a jsp and want to see the results I have to wait for tests, compile copy the war over deploy, server restart and then I have to log in again.
There's got to be a better way to do this. It's making my development speed slow to a crawl.

You can use maven tomcat plugin to run an in-memory tomcat over your maven project. Any jsp or static resource changes will apply immediately. Java code changes still require you to manually stop and start the server.
To do so use following maven goal
mvn clean tomcat:run

One other choice is jetty plugin. add jetty plugin to pom.xml,and run,that's ok.
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.11.v20130520</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<contextPath>/</contextPath>
</configuration>
</plugin>
</plugins>
</build>
run your application:
mvn jetty:run

Related

Deploy war file on apache tomcat upon creation

I'm not well experienced in java.
I build a UI using JSP for my servlets to get input data from users. Everytime I want to see the UI and how the Servlets are performing I have to do all thses steps over and over again,
create the war file by mvn clean install
Copy war file to Webapps folder
restart apache tomcat
View the result using the url
I want to know if there is a command that i can use to rerun apache tomcat with the war file im building at once, So that i only have to refresh the webpage to see the result. Or any method that is easier than above.
I use Intellij Idea.
Thanks in advance.
IntelliJ IDEA Community Edition does not support J2EE, but you can also achieve this in the following two ways. For full support of tomcat, you can buy IntelliJ IDEA Enterpries Edition.
Use maven-compiler-plugin
1) Add this plugin to your pom.xml:
<build>
<finalName>mvn-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
</plugins>
</build>
2) Then run this command:
mvn tomcat:run
Or Install Tomcat Runner Plugin
Refer to this link for usage of this plugin.
May be this will help you to deploy the war file on server

Vagrant & Maven Plugin strange behaviour

I've set up a Vagrant VM running Java/Maven/Tomcat. I've then taken an application I'm working on and copied the war to the shared folder that the VM has access to, namely webapps. I hunted around as didn't want to be copy / pasting when it should be automated and found reference to a maven plugin:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>/Username/Development/temp/vagrant-tomcat-2/vagrant-ubuntu-tomcat7/tomcat/webapps</outputDirectory>
</configuration>
</plugin>
</plugins>
I've added this to my build. Made a simple change to the index and ran clean install. My console panel looks as I'd expect it to, the war is being copied across - magic.
[INFO] Installing Username/Development/temp/vagrant-tomcat-2/vagrant-
ubuntu-tomcat7/tomcat/webapps/FitnessTracker.war to Username/.m2/repository/com/pluralsight/FitnessTracker/0.0.1-SNAPSHOT/FitnessTracker-0.0.1-SNAPSHOT.war
[INFO] Installing Username/Development/temp/vagrant-tomcat-2/Spring Tutorial - JPA Hibernate/spring_mvc_base-master/pom.xml to Username/.m2/repository/com/pluralsight/FitnessTracker/0.0.1-SNAPSHOT/FitnessTracker-0.0.1-SNAPSHOT.pom
I then reload the port and get a resource is not available error. Commenting out the plugin and running clean install again has the effect of copying the last changes I made to the webapp folder so that If I then check the port I'll see the changes.
What am I missing? I'm certain it's something daft.
The short short version: the maven plugin appears to be copying the last updated war instead of the current one, I think.

Integrated Tomcat in Maven reload sources?

I am using maven for my webapplication to build, start and handle the libraries. So I run tomcat7:run to develop my application... But if I change the code the tomcat will not automatic reload the code changes, so I need to restart. Before maven I use the "Sysdeo Eclipse Tomcat Launcher plugin" to run and create my project. This plugin allows to the see code changes instant and I know that the PLAY! Framework do the same. So it is possible to configure maven to reload my code changes on running? I will improve my work progress...
It is possible to automatically reload code changes by making sure the Tomcat context is reloadable.
The tomcat7:run goal allows you to enable context reloading with the contextReloadable parameter which must be configured in the configuration section of the plugin:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>

Trying to move to Jetty from Tomcat for testing on workstation, tomcat vs jetty

I been programming Spring/Web projects for sometime using eclipse and tomcat but now that I am getting into Maven I am also thinking about using jetty for my workstation testing.
I made a sample web app and if I run it on tomcat from eclipse I goto http://localhost:8080/TestJetty/ but if I do a mvn jetty:run I have to access it from http://localhost:8080/
Why is that?
Also can I setup eclipse to run jetty? whats the pros and cons of both
Normally with "jetty:run" goal of maven jetty plugin the context path is /, unless it is overridden with a contextPath configuration entry:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>Your version..</version>
<configuration>
<webApp>
<contextPath>/mycontextpath</contextPath>
</webApp>
</configuration>
</plugin>
From within Eclipse probably it is your project name that is being used as the context path.
Regarding pros and cons, it simply is your level of comfort, I prefer command line and so would normally run it outside of eclipse using "mvn jetty:run"

Maven and GWT (and Eclipse) - Does it really work?

Over the past few days I have been trying to create/run a project in Eclipse using the gwt-maven-plugin and keep running into roadblocks (see some of my previous questions). I like to use Maven to do my builds, but I'm at the point where I'm thinking of going the Ant build route because of the complications of using Maven.
Does anyone out there have it configured/working well? Is it just me or is this harder than it should be?
After much frustration trying to get things to play nicely together, this is the setup I have that "works" for me. "Works" meaning that I can create, run and debug a GWT project with tweaks, but it isn't the most elegant solution.
Create Project
Much of the steps are the same as Pascal's answer in this post: Maven GWT 2.0 and Eclipse. I'll list mine out to be clear.
In Eclipse (Helios) with m2eclipse and GWT Eclipse plugins installed:
Create a new Maven project using the gwt-maven-plugin archetype
Modify the pom.xml:
set <gwt.version property> to 2.0.4
(needs to be same as GWT Eclipse
Plugin version)
set <maven.compiler.source> and
<maven.compiler.target> properties to
1.6
remove <goal>generateAsync</goal>
from gwt-maven-plugin <plugin> config
add maven-war-plugin to pom.xml
maven-war-plugin example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<warSourceDirectory>war</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
Update project Properties:
Google -> Web Toolkit, check the "Use Google Web Toolkit" box, and ensure "Use default SDK (GWT-2.0.4) is selected.
Run Maven "gwt:eclipse" goal on project (sets up environment and launch config)
Copy *.launch file to workspace.metadata.plugins\org.eclipse.debug.core.launches
Restart Eclipse
Compile/Run Project
I created a Run Configuration that does mvn clean compile gwt:run. The gwt:run is necessary to copy the resources and lib jars into the war directory. However, it does not copy the web.xml from src/main/webapp/WEB-INF into war/WEB-INF/. So, I have to manually copy that file.
If I want to run my application, the above step is sufficient. However, if I want to debug the application, I launch it by choosing the Google "Web Application" configuration from Debug Configurations that was created when the .launch file was copied previously. This configuration allows for debugging (breakpoints etc.) without any other config or need for remote debugging.
It is harder then it should be, however it is possible. All hints posted here can do the trick. However you can still have classloading issues. I decided to switch to GWT 2.1 and use new abilities of JettyLauncher. You can create own jetty launcher like this:
public class MyJettyLauncher extends com.google.gwt.dev.shell.jetty.JettyLauncher {
#Override
protected WebAppContext createWebAppContext(TreeLogger logger, File appRootDir) {
return new WebAppContext(appRootDir.getAbsolutePath(), "/");
}
}
And then add -server MyJettyLauncher option to your gwt launcher configuration. With such configuration all the libraries are managed by m2eclipse (you can even remove GWT SDK from classpath) and there is no need to copy anything to WEB-INF/lib (you can remove gwt-servlet.jar which could be already there).
Ready launcher is here in tadedon library:
http://code.google.com/p/tadedon/source/browse/tadedon-gwt-dev/src/main/java/com/xemantic/tadedon/gwt/dev/JettyLauncher.java
Yes, in 2016 it does, quite nicely indeed. :)
I launch Tomcat from within Eclipse, I launch GWT codeserver (SuperDev mode) from Eclipse, I launch Chrome from Eclipse.
You will find quite recent and very valuable set-up tutorials on Brandon Donnelson's YouTube channel: https://www.youtube.com/user/branflake2267/videos
What is essential for me is Eclipse debugger for GWT SuperDevMode: https://sdbg.github.io/
I prefer to have my project "mavenized", and there is lot of Maven archetypes also provided by Brandon: https://github.com/branflake2267/Archetypes/tree/master/archetypes
The official starting point (not just) for downloading the GPE plugin (not to confuse with above mentioned debugger plugin) is on GwtProject.com: http://www.gwtproject.org/download.html
For me personally GPE itself has become rather optional "convenience" component. (Yes, refactoring and auto-completion are nice to have, but that's all it is needed for. :)
It is not a one-click solution, and I prefer it like that, as those tend to be black-boxes prone to breaking.
And BTW make sure to take a look at GWT Material: http://gwtmaterialdesign.github.io/gwt-material-demo/
(Currently playing with 2.8-beta1.)
For Eclipse I use: m2eclipse plugin (1.0). It works well with one or two minor things. Also download the m2eclipse-extras plugin to add SVN functionality AND Maven (or CVS if you prefer).
When you download then your project it reads the pom.xml and [re]creates the Eclipse configuration files like the mvn eclipse:eclipse command.
For GWT... I've used it too. It's a pretty twiked configuration but it works. I use GWT 2.0.3, the maven-gwt-plugin uses the dependencies to work (no ref to GWT SDK) and it can debug from Eclipse which is simply great.
You have to compile to a war directory (not the target/classes standard). But the details are in my work, so let me see it tomorrow and complete this answer :) Don't give up. It's a great thing to have GWT+Eclipse+Maven.
Edit: part of my configuration
<build>...
<outputDirectory>war/WEB-INF/classes</outputDirectory>
...
</build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<gwtVersion>${gwt.version}</gwtVersion> <!-- para forzar que use el de maven y no el SDK instalado -->
<disableCastChecking>true</disableCastChecking>
<disableClassMetadata>true</disableClassMetadata>
<runTarget>/subscriber/listSubscribers.htm</runTarget>
<webappDirectory>${basedir}/war</webappDirectory>
<soyc>true</soyc>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- dont know/remember if the jetty inside the gwt uses this... but it doesnt hurt-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.14</version>
<configuration>
<webAppConfig>
<contextPath>/magazine</contextPath>
<baseResource implementation="org.mortbay.resource.ResourceCollection">
<resourcesAsCSV>
${basedir}/src/main/webapp,
${basedir}/war
</resourcesAsCSV>
</baseResource>
</webAppConfig>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8888</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargets>
<scanTarget>${basedir}/war</scanTarget>
</scanTargets>
</configuration>
</plugin>
AND
For debugging I create two tasks:
1) maven build inside eclipse that runs two goals: war:exploded gwt:debug
The first one copies all the resources into war directory for gwt debug to use them.
Next the gwt is ready.
Maybe you need to execute gwt:compile for the first time
2) a Java Remote Application debug configuration, with your project selected.
You run this configuration when the gwt:debug is "listening at port 8000"
AND: this is in a parent pom.xml (sorry I'll edit this post later :)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
<warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
<webappDirectory>${basedir}/war</webappDirectory>
<warName>${artifactId}</warName>
</configuration>
</plugin>
helios wrote good explanation. But it's not actual at the moment. So I advice you to try my modern example of EAR application running on GlassFish and with full debug support.

Categories

Resources