maven tomcat7 plugin authentication fail, 403 Forbidden - maven

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>

Related

Hot deployment failure with Maven jetty plugin on Windows

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>

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

Why is my ${user.home} variable resoled at build time

I have a JHipster generated application with an YAML property file that looks like this:
storage:
location: ${user.home}/my/folder
My problem is that the variable ${user.home} is resolved at build time, when I run mvn package (on Jenkins). So the property is already resolved in the resulting artifact, hence when I deploy on on my server, that path contains the resolved home of the user Jenkins.
Anybody know who is doing this and why? I was expecting that the variable would be resolved at runtime.
Thanks.
Valentin
I'm not totally sure of how JHipster builds on top of Spring Boot, but my guess would be that it's Maven's resource filtering that's expanding ${user.home} at build time. It's enabled by default by spring-boot-starter-parent for application.properties and application.yaml in src/main/resources.
This Spring Boot issue contains some more information, along with details of a configuration change that you may like to make so that ${…} entries are no longer filtered:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>

Automatically publish JavaDoc as a functioning website on remote machine

Is there a way of automatically publishing as live website javadocs after uploading it to Nexus Maven repository? I have some packages, which are under constant development and I'd like to have the docs for them available for browsing by other team members straight after uploading updated code to our remote repository.
Is there any ready solution for doing that or would I have to write say a shell script (executed by Maven after successfull deployment of the code to the remote repo), which would copy the docs to a remote location on a web server?
I know that Nexus Professional allows to view javadocs out of the box, but even for 10 users it is a bit pricey, so I'd appreciate a different solution :-)
I'm using Eclipse#Windows + Maven 2.
Thanks!
If your project is open-source and is released to Maven Central then your javadoc will be available at javadoc.io automatically.
The url is of the form: http://www.javadoc.io/doc/[groupId]/[artifactId]. For example, I have my javadoc for my project at www.javadoc.io/doc/me.ramswaroop.jbot/jbot
Nexus Open Source as well as Nexus Professional support the site repository format, which allows you to host Maven produced sites. If you set up publishing a Maven site that includes Javadoc as part of your build you can have them accessible there.
The other thing you can do is just publish javadoc and source artifacts as part of you build and then Eclipse will be able to automatically download them from Nexus and you therefore wont even need a website with the javadoc on it for you developers.
Of course other people might want the site though.
Documentation on all that is available in the Nexus book as usual.
A bit late for reply, but someone else might need it in future. I didn't try the solution you proposed instead using one utilizing Maven Wagon plugin. Basically I first upload the jar with javadoc to webserver using sftp protocol and then unzip it using ssh command.
So parts of my parent POM, which configure the plugin look as follows:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<executions>
<execution>
<id>upload-javadoc</id>
<phase>deploy</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<serverId>my_id</serverId>
<fromDir>${local.dir}</fromDir>
<includes>${javaDoc.file}</includes>
<excludes>pom.xml</excludes>
<url>${remote.url}</url>
<toDir>${remote.dir}</toDir>
</configuration>
</execution>
<execution>
<id>execute-test-commands</id>
<phase>deploy</phase>
<goals>
<goal>sshexec</goal>
</goals>
<configuration>
<serverId>my_id</serverId>
<url>${remote.url}</url>
<commands>
<command>mkdir -p ${www.dir}</command>
<command>unzip -o ${remote.dir}/${javaDoc.file} -d ${www.dir} > latest_unzip_log.txt</command>
</commands>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
And then just call the plugin in child pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
So that's my solution, but I guess Manfred's is much simpler.
Ps.
Having the Javadoc available only in Ecplise (which I do anyways) was not the goal as the purpose was for the Javadoc to be available for other project members through a website.
Another option to host javadocs is https://docshoster.org/. It can automatically pickup from maven. There is an api to upload directly as well.

Deploying Maven project to JBoss AS7 (standalone)

I am new to JBOSS AS7, and am strictly using MAVEN 3 via command line. I would like to deploy the *.war of my project to JBOSS AS7 without ECLIPSE. I have spent couple of days Googling and trying out difference approaches. I am able to deploy the *.war to Tomcat. I would highly appreciate any help on this. So far this is what I have done:
I have entered the server info(Jboss) to C:\maven\conf\settings.xml
I have included the plugin to the POM
I think I may be declaring the path to JBoss AS7 within my JBOSS plugin wrong.
This is how I am including the plugin in the POM file:
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.0.2.Final</version>
<configuration>
<url>http://localhost:8080/
<server>jboss</server>
<path>/web-app</path>
<configuration>
</plugin>
</plugins>
Did you have a look at the README on the corresponding GitHub page:
https://github.com/jbossas/jboss-as-maven-plugin
When deploying to your localhost (which is the default value) you don't need to define the <url> in the <configuration>, as well as the <server> and <path> elements (besides: I haven't seen a folder named wep-app in AS7).
We run a project where this works even without touching the settings.xml.
So when you have checked this, post what exactly goes wrong, what is the concrete failure message and what is the maven command you use (mvn jboss-as:deploy).

Resources