How to deploy JSP changes in a maven application?

I have a maven web application. I am using the springsource toolkit and its built-in tc server.

Every time I make any changes, I have to run mvn clean install and reboot the server. Even for JSP changes.

Is there a way to make JSP changes, and they are reflected in the browser when updating, like a regular web application (and not a maven application).

I searched through the Internet, but so far have not achieved anything.

Still no clue. This makes the development process extremely slow. I looked into jrebel, but its not free, and I'm not looking for hot deployment of classes, but just hot deployment of JSP, javascripts, css, etc.

+4
source share
4 answers

You can use the Eclipse Filesync plugin for this . You can configure the plugin to display the maven output folder in the application server directory

I know this is not maven, but it works.

Perhaps this question will give more information.

+3
source

I am currently using a profile to copy the JSP to my target directory, which I call from Eclipse when I need JSP updates. You can also copy class files this way by adding execution.

<profile> <id>copyJsps</id> <build> <plugins> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <configuration> <outputDirectory>${basedir}/target/app/WEB-INF/jsp</outputDirectory> <resources> <resource> <directory>src/main/webapp/WEB-INF/jsp</directory> <filtering>true</filtering> </resource> </resources> </configuration> </plugin> </plugins> </build> </profile> 

Usage: mvn resources:copy-resources -PcopyJsps

+4
source

This is my simple solution (workaround?) When using JBoss on Linux. It must also be valid for Tomcat or any other container that supports cracked wars.

1. Use mvn war:inplace to create a detailed war in src/main/webapp . This will copy the classes and lib there. You do not need to repeat this step if you just change the JSP (or other / webapp / files). Alternatively, you can create symbolic links to classes and lib in src/main/webapp/WEB-INF :

 cd src/main/webapp/WEB-INF ln -s ../../../../target/classes mvn package ln -s ../../../../target/*/WEB-INF/lib 

2. In the deployment directory, create a symlink for src / main / webapp:

 cd $DEPLOYMEN_DIR ln -s $MYAPP_DIR/src/main/webapp myapp.war 

This makes changes to JSP and other webapp files instantly available. If you want to see changes in classes , then you can cause the application to reload only with my changing web.xml. You can run this script to control restart restart:

 #!/bin/bash while sleep 1; do if [[ -n $(find WEB-INF/classes -newer WEB-INF/web.xml -type f) ]];then date touch WEB-INF/web.xml fi done 

Run it from the src/main/webapp/ directory.

Note to JBoss AS 7: here, to trigger a reboot, you need to create the file myapp.war.dodeploy , and not touch web.xml

+1
source

You can easily clean and copy static files using clean and resource plugins, but it will not work for JSP files always. If the java source in the JSP files being copied introduces a new dependency, you are not going to copy it to the lib folder. In this case, the application will break into a ClassNotFoundException .

Even if it is copied, it can still break, because the server must be configured to scan the dependency folder and update the class path. And this is the beginning of a hot deployment, which I consider ( more ).

Try also the Vinay offer. Judging by his answer, it seems that the tc server supports dependency scanning by default, and with the correct maven build this might be a satisfactory solution.

To clear and copy static files from the source folder to where it is deployed:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>clean-loaded</id> <phase>compile</phase> <goals> <goal>clean</goal> </goals> <configuration> <excludeDefaultDirectories>true</excludeDefaultDirectories> <filesets> <fileset> <directory>${path.server.input}</directory> <followSymlinks>false</followSymlinks> <useDefaultExcludes>false</useDefaultExcludes> <includes> <include>**/*.jsp</include> <include>**/*.js</include> <include>**/*.html</include> <include>**/*.css</include> <include>**/*.png</include> <include>**/*.gif</include> <include>**/*.jpg</include> <include>**/*.jpeg</include> </includes> </fileset> </filesets> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-compile-output</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${path.server.input}</outputDirectory> <overwrite>true</overwrite> <includeEmptyDirs>true</includeEmptyDirs> <filtering>true</filtering> <resources> <resource> <directory>${path.jsp.source}</directory> <targetPath>${path.element.jsp.deploy}</targetPath> <includes> <include>**/*.jsp</include> </includes> </resource> <resource> <directory>${path.static.source}</directory> <targetPath>${path.element.static.deploy}</targetPath> <includes> <include>**/*.js</include> <include>**/*.html</include> <include>**/*.css</include> <include>**/*.png</include> <include>**/*.gif</include> <include>**/*.jpg</include> <include>**/*.jpeg</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> 

add this to the properties section:

 <path.server.input>ABSOLUTE_PATH_TO_DEPLOYED_WEBAPP_ROOT</path.server.input> <path.jsp.source>ABSOLUTE_PATH_TO_JSP_SOURCE_ROOT</path.jsp.source> <path.static.source>ABSOLUTE_PATH_TO_STATIC_SOURCE_ROOT</path.static.source> <path.element.jsp.deploy>REALTIVE_PATH_TO_JSP_DEPLOY_ROOT</path.element.jsp.deploy> <path.element.static.deploy>REALTIVE_PATH_TO_STATIC_DEPLOY_ROOT</path.element.static.deploy> 

Properties starting with path must be absolute paths or starting with ${project.basedir} or similar. Properties starting with path.element are relative paths, which means that they should not be added with / or starting with another property, which is an absolute path. This is because the resource plugin copies to outputDirectory/targetPath ( resources:copy-resources , resource )

In my experience, the IDE usually associates its actions with a clean and strict UI at compile time. In addition, the IDE usually has a way to display a shell command or maven user target to be visible from the user interface menu.

To run using clean-and-build

Plugins are already tied to the compilation phase. To ensure that a clean plug-in runs before the resource plug-in at the end of the compilation step, put them together at the end of the plug-ins section. It doesn’t matter if the plugin is defined twice, just make sure that when reading pom from above, the first pure definition of the plugin occurs before the definition of the first resource plugin.

Perform as a separate action

Change under the execution tag for both:

 <id>default-cli</id> <phase>never</phase> 

and now it will not start in the compile phase, but by a call from the command line:

 mvn clean:clean resources:copy-resources 

In this case, placing the plugin definitions in pom does not matter, since you define their order with the order of the command arguments. If this suits you, your IDE most likely has a way to display this command as a custom target visible from the UI menu.

In both cases, I recommend that you back up the project folder when you start it for the first time.

0
source

Source: https://habr.com/ru/post/1484028/


All Articles