mvn:deploy can not invoke tomcat manager - java

I am using mvn2, when I am trying to deploy my project using mvn:deploy command I am having error can not invoke Tomcat manager connection refused: connect below is my pom configuration
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost/manager</url>
<path>/scgtwitter</path>
<server>QA</server>
</configuration>
</plugin>
What could be the possible solutions?

The error indicates that either tomcat isn't up and running (so start it), or maybe your config is wrong.
Although I have not used that particular plugin, I have used a similar one, I imagine the principal is essentially the same. This what I have:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>localTomcat</server>
<path>/</path>
</configuration>
</plugin>
And in the ~/.m2/settings.xml, I have supplied the username/password for the tomcat manager app:
<servers>
<server>
<id>localTomcat</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
Run with with
mvn tomcat:deploy
or
mvn tomcat:redeploy

Related

Overriding Tomca7 Maven Plugin configuration

I am working in a project that uses a tomcat7-maven-plugin for testing, defined in the pom like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9092</port>
...
</configuration>
</plugin>
</plugins>
</build>
Is there a way to start this on a different port without editing the pom? When running mvn tomcat7:run -Dmaven.tomcat.port=9099 it still starts the tomcat on port 9092. I can't change the pom permanently due to others in the project desiring this default configuration, and I don't want to have to edit it locally every time I start the tomcat.
Thanks for help!

Change http port in wildfly maven plugin

I would like to change the default HTTP port using the wildfly-maven-plugin to 8380. Usually, I can do that changing the offset, but this is not working, my changes are ignored and HTTP port continues on 8080.
I'm starting wildfly in the same maven project, because this is way more practical (download and start automatically). Just like that:
mvn wildfly:run -Dwildfly.version=10.1.0.Final
My project contains JAR, WAR and EAR. Classic structure.
As I understood from another SO questions, I need to put the plugin entry in each pom.xml that needs to be ignored, putting <skip>true</skip> in pom.xml of the: root, WAR and JAR. Just like that:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
If I not skip this guys, the Wildfly try to deploy the JAR/WAR/Root, what is not my objective. I would like to deploy only the EAR.
To do that, I use the <skip>false</skip> only for pom.xml of the EAR:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
The localhost:8080/app/ works well after that.
But if I try to change the offset or http port, nothing different happens. This is some of the args that I already try on <configuration/> without success:
<server-args>
<server-arg>-Djboss.socket.binding.port-offset=300</server-arg>
</server-args>
<jvmArgs>-Djboss.socket.binding.port-offset=300</jvmArgs>
<jvmArgs>-Djboss.http.port=8380</jvmArgs>
The change that have some effect was:
<serverConfig>standalone.xml</serverConfig>
<server-args>
<server-arg>-Djboss.socket.binding.port-offset=300</server-arg>
</server-args>
<filename>${project.build.finalName}.ear</filename>
This also have changed the port (jvmArgs is deprecated):
<javaOpts>-Djboss.socket.binding.port-offset=300</javaOpts>
But in both cases the EAR application is not deployed...
Any idea? Thanks!
Finally, I found the solution.
The jvmArgs is deprecated. I used javaOpts:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<skip>false</skip>
<javaOpts>-Djboss.http.port=8380</javaOpts>
<filename>${project.build.finalName}.ear</filename>
</configuration>
</plugin>
Works!
You can use too:
<javaOpts>
<javaOpt>-agentlib:jdwp=transport=dt_socket,address=9087,server=y,suspend=n</javaOpt>
<javaOpt>-Djboss.http.port=8380</javaOpt>
</javaOpts>
To use more than one option for the JVM. In this example above I'm showing how to include a parameter to debug the Wildfly using the maven plugin.
But it's still a mistery why the EAR is not deployed when I use the offset configuration.
try not skipping the configuration :D
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<port>8380</port>
</configuration>
</plugin>

maven war application setting up contextroot

i am building a war application file using the below maven config, however when i start the application in tomcat the Context Root is set to "/CommerceApi-0.0.1-SNAPSHOT/"
I want this to be set to "/api",
any ideas?, below is the pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CommerceApi</groupId>
<artifactId>CommerceApi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>CommerceApiCommon</groupId>
<artifactId>CommerceApiCommon</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
There are three ways to do it:
1. If you are not using Eclipse/MyEclipse to deploy the application onto application server -
You need to make use of maven-war plugin, you can specify warName in configuration section.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warName>customwarname</warName>
</configuration>
</plugin>
2. If you are using Eclipse/MyEclipse to deploy the application onto application server -
If you are using eclipse and deploying war using eclipse then you can use following maven configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.10</version>
<configuration>
<wtpversion>2.0</wtpversion>
<wtpContextName>customwarname</wtpContextName>
</configuration>
</plugin>
Then, run following commands to update eclipse settings.
mvn eclipse:eclipse -Dwtpversion=2.0
Restart Eclipse and then navigate to project properties, Properties->Web to view the reflected changes in root-context value or navigate to Deployment Assembly of the project to view the changes
Note that above can be achieved using m2eclipse by adding a new plugin.
3. Application server specific:
You should prefer to follow server agnostic approach, but if are required to do it then you can configure root context url in server specific configuration file. You can find detailed approach here
Your application is not in charge to define its own context path. That's task of the container, the Tomcat in your case. Tomcat offers several options of how to set the context path. You may define the context path it in a context file or specify the context path in the manager application. If you use Jenkins or other CI tools you'd be able to specify the context path there, as well.
Best you read up on the options you have regarding your particular Tomcat version.
There are several options. Some are described in Define Servlet Context in WAR-File
Using tomcat you can also define the context.xml path: http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#containerConfigXML and maybe configure it in there: https://tomcat.apache.org/tomcat-7.0-doc/config/context.html
the fastest way os probably to change the final name (see other stackoverflow question).

Exclude application.properties when generating war using spring boot and spring-boot-maven-plugin

I am developing a web application using Spring Boot, and want to generate war instead of jar.
It works very fine using the conversion from jar to war described here : http://spring.io/guides/gs/convert-jar-to-war/
But I want to exclude the application.properties from the war, because I use #PropertySource(value = "file:${OPENSHIFT_DATA_DIR}/application.properties") to get the file path on production environment.
This method works when generating my war, but in eclipse I can't run my application because application.properties not copied at all to target/classes :
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
</excludes>
</resource>
</resources>
</build>
This method doesn't work at all, I think that spring-boot-maven-plugin doesn't support packagingExcludes :
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/classes/application.properties</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
Have you another suggestion?
Thanks
Try using the solution below. This will work:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
If you are using the above solution , while running the project in Eclipse IDE you may get error that the properties file is not found. To get rid of this you need to add the resources folder in Run as configuration.(Run configurations... -> Classpath -> User Entries -> Advanced... -> Add Folders)
When running in Eclipse, at your Run Configuration, you need to specify the path of the propeties to Spring Boot:
--spring.config.location=${workspace_loc:/YOURPROYECTNAME}/src/main/resources/
The solution I added is to unzip my packaged war, delete the file application.properties and create a new war named ROOT.war using maven-antrun-plugin and run some ant tasks.
this is what i added to my plugins in pom.xml :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<configuration>
<target>
<unzip src="target/${artifactId}-${version}.${packaging}" dest="target/ROOT/" />
<delete file="target/ROOT/WEB-INF/classes/application.properties"/>
<zip destfile="target/ROOT.war" basedir="target/ROOT" encoding="UTF-8"/>
<delete dir="target/ROOT"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I named my target war as ROOT.war because I am using tomcat on openshift PaaS, so I just copy my ROOT.war and push to my openshift repo. That's it
What I understand from your question is, you want to use application.properties for your development. But you dont want to use it for production.
I would suggest using Spring profiles to achieve this.
In your properties file
Create a profile for development. Put all your development properties under it.
Do not create a profile for production in your properties file.
When you are developing, set active profile to development, so that the properties are loaded from your application.properties file.
When you run it in production, set active profile to Production. Though application.properties will be loaded into your WAR, since there is no profile for production, none of the properties will be loaded.
I have done something similar using YML. I am sure there must be a way to do the same thing using .properties file too.
spring:
profiles.active: development
--
spring:
profiles: development
something:
location: USA
unit1: Test1
unit2: Test2
You could change the profile in run time using
-Dspring.profiles.active=production
Try to using this solution:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.version}</version>
<configuration>
<addResources>false</addResources>
</configuration>
</plugin>
<addResources>false</addResources> will keep properties when you run mvn spring-boot:run

jboss-as-maven-plugin can't deploy to remote Jboss?

I've tried for days to use jboss-as-maven-plugin to deploy web projects to remote Jboss as 7,but it didn't work. The following is my pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.3.Final</version>
<configuration>
<skip>true</skip>
<hostname>127.0.0.1</hostname>
<port>9999</port>
</configuration>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I have error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.3.
CR1b:deploy (default) on project MessagePushX-RELEASE: Could not execute goal de
ploy on test.war. Reason: java.net.ConnectException: JBAS012144: Could no
t connect to remote://192.168.1.104:9999. The connection timed out -> [Help 1]
[ERROR]
What is wrong?
The error message clearly says it can't connect to "remote://192.168.1.104:9999". Verify that it's the correct configuration and verify your connectivity to that destination.
You can try
telnet 192.168.1.104 9999
from your machine to see if you've got connection.
This may not be the solution you want, but it's one we use.
You can map a network drive to the deploy folder you want your files in, then have maven build it's output to that folder.
For example, on our local machines, maven builds the jar directly in the deploy folder in JBoss.
Another option is to configure JBoss to use an alternate deploy folder in addition to the default. Then have maven build to this alternate folder where JBoss will pick your files up from.
Just a couple of different options to think about if this other one still isn't working for you.
Changes to standalone.xml
Location: (/usr/local/share/jboss/standalone/configuration/standalone.xml)
modified standalone to have auto-deploy zipped true (so as no need to create war.dodeploy file) and auto-deploy-exploded false
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
<deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" auto-deploy-zipped="true" auto-deploy-exploded="false"/>
added jsp-configuration
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
<configuration>
<jsp-configuration development="true"/>
</configuration>
added jboss-as-configuration in maven pom.xml
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.3.Final</version>
<configuration>
<hostname>192.168.0.105</hostname>
<port>9999</port>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
you should have your jboss instance started from eclipse or outside and bind to same IP instead of localhost or 127.0.0.1.
You can do this either from your command line or from eclipse by changing host to your IP address: 192.168.0.105
After this you can use the following maven goal to redeploy changes after each change. Also please note you might have to use deploy initially and then redeploy.
-e -X jboss-as:redeploy

Categories