Hot deployment failure with Maven jetty plugin on Windows - maven

I have configured the Jetty Maven plugin to run my compiled war.
Here is the relevant part of my pom.xml.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.50.v20221201</version>
<configuration>
<war>${jway.webapps.dir}/myapp.war</war>
<scanIntervalSeconds>2</scanIntervalSeconds>
</configuration>
</plugin>
If I execute mvn jetty:run-war, my war is build and Jetty serves the app as expected.
I have configured scanIntervalSeconds to allow hot redeploy.
However, if I rebuild using mvn install, I get the following error during redeployment:
java.lang.IllegalStateException: Failed to delete temp dir F:\...\myproject\target\tmp
at org.eclipse.jetty.webapp.WebInfConfiguration.configureTempDirectory (WebInfConfiguration.java:532)
at org.eclipse.jetty.webapp.WebInfConfiguration.resolveTempDirectory (WebInfConfiguration.java:424)
at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure (WebInfConfiguration.java:140)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure (WebAppContext.java:488)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:523)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart (JettyWebAppContext.java:397)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:73)
at org.eclipse.jetty.maven.plugin.JettyRunWarMojo.restartWebApp (JettyRunWarMojo.java:113)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo$1.filesChanged (AbstractJettyMojo.java:472)
at org.eclipse.jetty.util.Scanner.reportBulkChanges (Scanner.java:848)
at org.eclipse.jetty.util.Scanner.reportDifferences (Scanner.java:765)
at org.eclipse.jetty.util.Scanner.scan (Scanner.java:641)
at org.eclipse.jetty.util.Scanner$1.run (Scanner.java:558)
at java.util.TimerThread.mainLoop (Timer.java:555)
at java.util.TimerThread.run (Timer.java:505)
It seems that Jetty wants to delete the file, but Windows locks the file. In the plugin documentation, I have not found any configuration which seems to be helpful. Furthermore I have nothing found on Google. Is there any way to solve this issue?
I don't know if its relevant, but I do not use the jetty:run goal, because my war is build using a third party tool and I do not have a standard directory structure.

The jetty documentation contains a section about Troubleshooting Locked Files on Windows.
So I updated my plugin config according to the documentation:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.50.v20221201</version>
<configuration>
<war>${jway.webapps.dir}/myapp.war</war>
<scanIntervalSeconds>2</scanIntervalSeconds>
<webApp>
<_initParams>
<org.eclipse.jetty.servlet.Default.useFileMappedBuffer>false</org.eclipse.jetty.servlet.Default.useFileMappedBuffer>
</_initParams>
</webApp>
</configuration>
</plugin>

Related

Vaadin 8 + AudioVideo Addon: "Failed to load the widgetset"

I added the AudioVideo Addon to my Vaadin 8 (version 8.7.2, Maven 3, Tomcat) project and everything woks fine in my Eclipse development environment (I did run Maven clean install). But if I export the WAR file to the deployment server the app fails to start with the following error:
Failed to load the widgetset: ./VAADIN/widgetsets/AppWidgetset/AppWidgetset.nocache.js?1556793473728
I found the following in my Maven POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Exclude an unnecessary file generated by the GWT compiler. -->
<packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
</configuration>
</plugin>
I think I need to change something in the Maven config. I tried the "packagingIncludes" instead of "packagingExcludes" but this did not help.
I would be glad for your help since I cannot do "experiments" on the deployment server.
How do I have to configure Maven or what else do I have to do to get the following folder from the eclipse depolyment environment into my exported WAR file?
myApp\target\myApp-0.0.1-SNAPSHOT\WEB-INF\classes\VAADIN\widgetsets\AppWidgetset

How to hot redeploy non-active maven project via jetty-maven-plugin

I'm trying to evaluate jetty for rapid development or project which is currently running on tomcat. My configuration looks like
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.3.v20140905</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<webApp>
<descriptor>${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml</descriptor>
<resourceBases>
<directory>${basedir}/src/main/webapp</directory>
<directory>${basedir}/../SharedWeb/src/main/webapp</directory>
</resourceBases>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
<contextPath>/test</contextPath>
</webApp>
</configuration>
</plugin>
I have main war depending on SharedWeb war via war overlay mechanism. I specify resourceBases for both maven projects so changes in resources are scanned automatically and reloaded on the fly and all working fine. Also when I compile classes in main war, jetty restarts automatically, reloading the latest changes. But when I try to change any class in SharedWeb project and compile it, the class is not reloaded. I'm just wondering if there is a way to make embed jetty to reload classes from SharedWeb automatically? I understand that jetty-maven-plugin uses SharedWeb war from local maven repository, so I need to install SharedWeb artifact before I can see any changes. So I don't have high expectations, but maybe I'm missing something.
Ivan,
The plugin is using the classes and resources from your dependency
war, NOT from the that you have added. The
simply tells jetty to watch that location and redeploy if something in
it changes - it does NOT put it onto the classpath.
You need to tell jetty to use the classes and resources from your
dependency war's project, NOT the war artifact.
So do something like:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.3.v20140905</version>
<configuration>
<webApp>
<!-- tell jetty to use the classes from the dependency
webapp project directly -->
<extraClassPath>${basedir}/../SharedWeb/target/classes</extraClassPath>
<!-- tell jetty to use both this project's static
resources, and those of the dependency webapp project -->
<resourceBases>
<directory>${basedir}/src/main/webapp</directory>
<directory>${basedir}/../SharedWeb/src/main/webapp</directory>
</resourceBases>
</webApp>
<scanIntervalSeconds>3</scanIntervalSeconds>
<!-- tell jetty to watch the dependency webapp project classes
dir for changes -->
<scanTargets>
<scanTarget>${basedir}/../SharedWeb/target/classes/</scanTarget>
</scanTargets>
</configuration>
</plugin>
Jan
Since there doesn't seem to be a good prior answer that is specific enough for this question (aka <scanTarget>) I'll just post this new one and tweak the title to make it easier to find in the future.
What you are looking for is <scanTarget>, as that will allow you to customize the scanning locations for changed content that will trigger a hot redeploy.
The jetty-maven-plugin intentionally does not set this up for custom <resourceBases> as there are far to many legitimate use cases where this can cause aggressive / too often / or infinite redeploys. It was decided that it was best to break from "convention over configuration" for <scanTarget> entries and allow the developers to decide what should be scanned for changes.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.3.v20140905</version>
<configuration>
...
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargets>
<scanTarget>${basedir}/../SharedWeb/src/main/webapp/</scanTarget>
<scanTarget>${basedir}/../SharedWeb/target/classes/</scanTarget>
</scanTargets>
</configuration>
</plugin>

WSO2ESB - Building a CAR file with Maven

Using WSO2 Developer Studio (version 3.7.0), I have created a WSO2 ESB proxy service with a sequence in a "ESB Config Project", this proxy service using a wsdl file located in a "Registry Resources Project". I also created a "Composite Application Project" to generate my .car file (including proxy service, sequence and resources), and deployed this file in my WSO2 ESB installation with success.
Now I am trying to generate (then deploy) the .car file using maven command.
I first tried this solution : https://docs.wso2.com/display/DVS370/Deploying+a+CAR+File+with+the+Maven+Plug-In.
When executing command "mvn clean install" on my ESB Config Project, I get this error :
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory ([ESB Config Project Path]\target\capp).
Please verify you invoked Maven from the correct directory. -> [Help 1]
Indeed, the install goal is configured to be executed in "target/capp" directory :
<directory>target/capp</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<extensions>true</extensions>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>clean</argument>
<argument>install</argument>
<argument>-Dmaven.test.skip=${maven.test.skip}</argument>
</arguments>
</configuration>
</execution>
...
Then I tried to create a "Maven Multi Module Project", as suggested here : maven build for WSo2 artifacts, but I did not found any solution to make it work :
following the steps from this documentation (https://docs.wso2.com/display/DVS310/Using+Maven+with+Developer+Studio?src=search), I created a "Maven Multi Module Project", and selected my Config, Resources and Composite projects as children. Then I launched the "mvn clean install" command, but still getting the error on ESB Config Project (no POM in target/capp folder).
Actually, I just did not found any information about these errors, and do not understand why the WSO2 documented solution did not work for me.
Does anyone have a suggestion about that ? How does WSO2 Developer Studio generate the .car file ?
Thanks
I found another answer for this problem. The exec-maven-plugin version seems to be buggy. The WSO2 Developer Studio 3.7.0 add a buggy version (1.2) when creating the project. You just have to change the artifact from:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
to:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
See this as a complementary information:
exec-maven-plugin says cannot run specified program, even though it is on the PATH
I finally succeded in generating a .car file and creating a maven multi module project.
I was trying to create all my maven projects with WSO2 Developer Studio 3.7.0, although the sample said to use version 3.2.0. As the WSO2's maven plugins versions change, it now works fine for me, executing maven install with plugin v2.0.4.
And a maven multi module project is finally just a maven project with modules, so it is OK.

Flyway seems to not be overriding properties

I have my standard flyway config in my pom file and I am trying to override in through system properties, as mentioned here.
Here is my configuration in the pom file:
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<url>dbUrl</url>
<user>dbUser</user>
<password>dbPass</password>
<schemas>
<schema>core</schema>
<schema>public</schema>
</schemas>
</configuration>
</plugin>
And following is the command line that I'm running:
mvn clean compile flyway:migrate -Dflyway.url=anotherDbUrl -Dflyway.user=anotherDbUser -Dflyway.password=anotherDbPass
The documentation in the above link says System properties > Maven properties > Plugin configuration. Am I missing something?
Good catch. This seems to have broken along the way. Could you please file an issue? I'll fix this in time for 2.2.1.

maven tomcat7 plugin authentication fail, 403 Forbidden

I'm posting this after weeks of effort. I try and try because I felt guilty of posting this because there are thread similar to this. But still I'm getting slightly different error. So what I have is a very simple spring(no need to be spring of course bcz problem is with maven) application with maven.
This is plugins section from my pom.
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<username>tomcat</username>
<password>s3cret</password>
<path>/Test</path>
<port>8080</port>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
Earlier I have problems with maven tomcat plugin not working with tomcat 7 etc etc but now with "tomcat7-maven-plugin" there are solved. I'm using 'http://localhost:8080/manager' as the URL. For almost all threads about this maven tomcat compiler plugin are about build failure. But my build succeed(I run as tomcat7:deploy). Problem is tomcat is replying
tomcatManager status code:403, ReasonPhrase:Forbidden
along with the html that we see when we got a authentication failure on browser. The same code works fine under my Linux box. I try different scenarios of using server element in settings.xml which is inside .m2 and inside maven_home/conf etc. Still not working.
As I figure out maven cannot authenticate tomcat. username and password is find and I can log in using GUI. So expecting a help here.
p.s - my tomcat-users.xml fiel
<role rolename="manager-gui" />
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Url is not correct try with :
<url>http://localhost:8080/manager/text</url>
what is the content of tomcat-users.xml file. Did you correctly set permissions ?
See http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html
I could get tomcat deploy work but environment is different. So anyway I'm going to tell how I could do it since may be It'll help someone.
In this case I have tomcat6 as my web container and I'm using eclipse Helios as the IDE.
First of all I have haven environmental variables set as described in the maven web site(Maven download installation help). Which means environmental variables M2_HOME and M2 are set and M2 is in my path variable.
Then in eclipse I have maven installation folder, local repository(In case if it is not default) and settings.xml file correctly. (These setting are in Window -> Preferences -> Maven -> Installations and User settings)
In tomcat_home\conf\tomcat-users.xml I have created user with the role manager-script.(Note that here I use tomcat6)
< role rolename="manager-script"/>
< user password="s3cret" roles="manager-script" username="tomcat"/>
In POM.xml I have maven tomcat plugin defined as follows.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>TomcatServer</server>
</configuration>
</plugin>
Then on eclipse Run Configurations I create a configuration to run goal "tomcat6:deploy" ( This site from apache says tomcat:deploy is the goal but it didn't work).
Which runs perfectly and deploy my app to the container. Once it is deployed app need to be undeplyed using "tomcat6:undeploy" before deploying again.
I'm not a expert about this and still I have doubts on some facts. But since I saw this question in lots of places I thought this will help someone it the same problem.
Thank you
Today I tried same application with Tomcat 7. I need to change plugin artifactId to "tomcat7-maven-plugin". And I have to change the url as "http://localhost:8080/manager". After doing these changes deploy works fine. Also I figure out that maven read settings.xml inside .m2 folder. There is also a settings.xml file inside mvaen_home/conf but it is not the one it read. Another thing I found is there is no undeploy for tomcat7 for tomcat6 there was a undeploy.
Sometimes when all from the above criteria are matched and You still get the error there is a chance that You are using mvn tomat7:deploy command. And at the same time the server is maintained by Eclipse wchich dosen't go heand in heand. You could stop the server in Eclipse IDE and than try again with the mvn command.
After trying several things the following configuration worked for me.
Please give it a try
tomcat-users.xml
<role rolename="manager-gui"/>
<user password="tomcat" roles="manager-gui" username="tomcat"/>
pom.xml
<!-- Maven Tomcat Plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/html</url>
<username>tomcat</username>
<password>tomcat</password>
<update>true</update>
<path>/Test</path>
</configuration>
</plugin>

Resources