Why can't I shutdown tomcat 7 embedded from maven plugin? - windows

I'm using tomcat7-maven-plugin 2.2 to run a webapp from command line (I'm on Windows 8.1, Java 1.7.0_51 and Maven 3.2.1).
This is the configuration (pretty straightforward, I guess):
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<address>localhost</address>
<port>8080</port>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
I run Maven with mvn tomcat7:run and it starts correctly, the server starts up, the webapp loads, and I can interact with it.
The command prompt in which I run Maven is busy showing Tomcat output (this looks fine to me):
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <project-name-here> 0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) # <project-name-here> >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # <project-name-here> ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 25 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # <project-name-here> ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) # <project-name-here> <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) # <project-name-here> ---
[INFO] Running war on http://localhost:8080/
[INFO] Using existing Tomcat server configuration at c:\workspace\<project-name-here>\target\tomcat
[INFO] create webapp with contextPath:
apr 01, 2014 10:39:50 AM org.apache.coyote.AbstractProtocol init
Informazioni: Initializing ProtocolHandler ["http-bio-127.0.0.1-8080"]
apr 01, 2014 10:39:50 AM org.apache.catalina.core.StandardService startInternal
Informazioni: Starting service Tomcat
apr 01, 2014 10:39:50 AM org.apache.catalina.core.StandardEngine startInternal
Informazioni: Starting Servlet Engine: Apache Tomcat/7.0.47
apr 01, 2014 10:39:52 AM org.apache.coyote.AbstractProtocol start
Informazioni: Starting ProtocolHandler ["http-bio-127.0.0.1-8080"]
Then, I want to shutdown the server: I run mvn tomcat7:shutdown from a separate command prompt, but all I get is this:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <project-name-here> 0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:shutdown (default-cli) # <project-name-here> ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.083 s
[INFO] Finished at: 2014-04-01T10:39:59+01:00
[INFO] Final Memory: 9M/154M
[INFO] ------------------------------------------------------------------------
"cmd" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.
That last line reads:
"cmd" is not a recognized internal or external command, an executable
or a batch file.
I can stop Tomcat from the first command prompt hitting Ctrl+C, but since I need to pass all this others, I'd like to offer them a script to start the webapp and a script to stop it.
What's wrong? Is it a plugin error? Is it a configuration error on my side?
EDIT
If I add <fork>true</fork> to the POM, the server crashes with this error:
[...]
Informazioni: Starting service Tomcat
apr 03, 2014 2:05:29 PM org.apache.catalina.core.StandardEngine startInternal
Informazioni: Starting Servlet Engine: Apache Tomcat/7.0.47
apr 03, 2014 2:05:31 PM org.apache.coyote.AbstractProtocol start
Informazioni: Starting ProtocolHandler ["http-bio-127.0.0.1-8080"]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.711 s
[INFO] Finished at: 2014-04-03T14:05:31+01:00
[INFO] Final Memory: 26M/368M
[INFO] ------------------------------------------------------------------------
ERROR: IllegalAccessException for stop method in class org.apache.tomcat.maven.plugin.tomcat7.run.ExtendedTomcat
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.maven.common.run.EmbeddedRegistry.shutdownAll(EmbeddedRegistry.java:110)
at org.apache.tomcat.maven.common.run.EmbeddedRegistry$1.run(EmbeddedRegistry.java:69)
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardServer[-1]]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
at org.apache.catalina.startup.Tomcat.stop(Tomcat.java:351)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardService[Tomcat]]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
at org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:753)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardEngine[Tomcat]]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
at org.apache.catalina.core.StandardService.stopInternal(StandardService.java:502)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
... 9 more
Caused by: java.lang.NoClassDefFoundError: org/apache/catalina/core/ContainerBase$StopChild
at org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:1173)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.core.ContainerBase$StopChild
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
... 13 more

As far as I know you need to use Ctrl + c after starting Tomcat server with mvn tomcat7:run to shut it down as it's attached to the current Maven run.
The shutdown goal is used to be called after e.g. performing some tests (integration tests) to finish all the job in a clean way.

have a look at the fork option http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/run-mojo.html#fork
So with this option you are able to start embeded tomcat run some tests then shutdown.
HTH

An alternative is if the Tomcat maven plugin had a way to enable the shutdown port (default 8005) then you can just send the default shutdown string (default "shutdown") to shut it down.
Using a JMX client, the shutdown port is set to -1 when I run the plugin run goal.

Related

How to set up swagger-jaxrs-server

I have generated swagger-jaxrs-server from open api code generator using this petstore.yaml from swagger openapi as input . I want to run sever in STS as maven project.
I tried
1) Adding Tomcat7 plugin in porm.xml
2) Maven --> update project
3) Run as --> maven clean
4) Run as --> maven build --> goal:tomcat7:run
But I am getting error as
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< io.swagger:swagger-jaxrs-server >-------------------
[INFO] Building swagger-jaxrs-server 1.0.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes # swagger-jaxrs-server >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # swagger-jaxrs-server ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Spring\openapi\jaxrs-spec-server-generated\jaxrs-spec-server-generated\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # swagger-jaxrs-server ---
[INFO] No sources to compile
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes # swagger-jaxrs-server <<<
[INFO]
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) # swagger-jaxrs-server ---
[INFO] Running war on http://localhost:8080/swagger-jaxrs-server
[INFO] Creating Tomcat server configuration at D:\Spring\openapi\jaxrs-spec-server-generated\jaxrs-spec-server-generated\target\tomcat
[INFO] create webapp with contextPath: /swagger-jaxrs-server
Jan 23, 2023 12:22:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 23, 2023 12:22:09 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jan 23, 2023 12:22:09 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Jan 23, 2023 12:22:11 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]

Jenkins is unable to execute Cucumber tests using Maven Surefire, Spring Boot and JUnit5

I am using spring-boot-starter-parent:2.2.6.RELEASE and cucumber-java8:5.6.0 to execute e2e tests using Cucumber Runner/Spring Boot/JUnit5/Maven Surefire. I have installed latest Jenkins Community LTS v2.222.1 on a Linux VM and connected my laptop as a slave.
When I execute the tests on my laptop using IDE / command prompt it works fine (using mvn clean test). However same tests are not running when triggered from Jenkins. It's bit confusing since I am using same config/tools.
Jenkins Console O/P:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Jenkins\workspace\Sanity\core\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # project-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseForFeature
INFO: File {0} does not contain features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'C:\Users\User\AppData\Local\Temp\2\cucumber5203280546924184867.json' contains 0 features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportBuilder generateErrorPage
INFO: Unexpected error
net.masterthought.cucumber.ValidationException: Passed files have no features!
...
IDE Console O/P:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Code\project\core\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # project-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.x.y.z.CucumberTests
2020-04-07 13:22:52.330 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper : Neither #ContextConfiguration nor #ContextHierarchy found for test class [com.x.y.z.stepdefs.LogVerificationSteps], using SpringBootContextLoader
...
CucumberTests.java:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "de.monochromata.cucumber.report.PrettyReports:target"},
features = "src/test/resources/features")
public class CucumberTests {
}
This is multi-module maven project, the features are available under:
root
\__core
\__src/test/resources/features/*
So basically in Jenkins features/tests are not being run at all - why is it happening, any idea folks?

Is there a way to porsue with maven build after running wildfly:run goal?

I would like to complete Maven build lifecycle after wildfly:run goal's execution.
The fact is that wildfly:run goal starts a standalone application server and from that point the CLI shows Wildfly's Log messages only.
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:run (default) # PrimeFaces1 ---
[WARNING] The POM for org.wildfly.plugins:wildfly-plugin-core:jar:2.1.0.Beta1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] JAVA_HOME : C:\Program Files\Java\jdk1.8.0_201\jre
[INFO] JBOSS_HOME: C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\wildfly-18.0.1.Final
[INFO] JAVA_OPTS : -Xms64m -Xmx512m -Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Djboss.modules.system.pkgs=org.jboss.byteman
[INFO] Server is starting up. Press CTRL + C to stop the server.
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] XNIO NIO Implementation Version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
13:04:25,585 INFO [org.jboss.modules] (main) JBoss Modules version 1.9.1.Final
13:04:26,228 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.11.Final
13:04:26,248 INFO [org.jboss.threads] (main) JBoss Threads version 2.3.3.Final
13:04:26,472 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: WildFly Full 18.0.1.Final (WildFly Core 10.0.3.Final) starting
13:04:27,800 INFO [org.wildfly.security] (ServerService Thread Pool -- 28) ELY00001: WildFly Elytron version 1.10.4.Final
Actually I would like to run next goals but the server takes control of the CLI
Besides, in the pom.xml, I've tried to sobstitute wildfly:run with the wildfly:deploy goal, which deploy the artifact on the local JBOSS server(already started), And in this case the maven build goes on until the end.
[INFO] --- maven-war-plugin:2.2:war (default-war) # PrimeFaces1 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [PrimeFaces1] in [C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\PrimeFaces1-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\src\main\webapp]
[INFO] Webapp assembled in [128 msecs]
[INFO] Building war: C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\PrimeFaces1-1.0-SNAPSHOT.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) < package # PrimeFaces1 <<<
[INFO]
[INFO]
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) # PrimeFaces1 ---
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] XNIO NIO Implementation Version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
[INFO]
[INFO] --------------------< com.mkyong.core:PrimeFaces2 >---------------------
[INFO] Building PrimeFaces2 1.0-SNAPSHOT [3/3]
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) > package # PrimeFaces2 >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # PrimeFaces2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces2\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # PrimeFaces2 ---
[INFO] Nothing to compile - all classes are up to date
As you can see in this case the deploy goal doesn't "lock" the CLI but the build process still continues until the end
This behaviour is expected for the wildfly:run command, you're supposed to interrupt the server from the outside once you're done testing. Quoting the goal's documentation,
This goal will block until cancelled or a shutdown is invoked from a management client.
If that doesn't suit you, you can instead use wildlfy:start followed by wildfly:deploy.

jenkins deploy war/ear to a container - why the .war file is renamed before it is deployed on the remoteserver

I'm new to jenkins and have a problem. I created a maven project (maven integration plugin 2.12.1) in jenkins (ver. 1.638). I got the source-code via git (maven web application).
Everything works fine, but at the end the .war which is moved/deployed via deploy plugin to the remote server has a wrong name.
I dont know why the .war file is renamed before it is deployed on the remoteserver.
It is called services.war instead of services_admin.war.
Screenshot jenkins:
https://i.stack.imgur.com/uc5wK.png
pom.xml:
<groupId>services_admin</groupId>[enter image description here][1]
<artifactId>services_admin</artifactId>
<name>services_admin</name>
<description>services_admin</description>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${basedir}/src/main/java</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>1.5</wtpversion>
<additionalProjectFacets>
<jst.java>6.0</jst.java>
<jst.web>2.5</jst.web>
</additionalProjectFacets>
<additionalBuildcommands>
<buildcommand>org.eclipse.wst.common.project.facet.core.builder</buildcommand>
<buildcommand>org.eclipse.wst.validation.validationbuilder</buildcommand>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
</plugins>
<finalName>services_admin</finalName>
</build>
Build log:
[INFO] ------------------------------------------------------------------------
[INFO] Building services_admin 2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # services_admin ---
[INFO] Deleting D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # services_admin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 120 resources
[INFO] Copying 307 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) # services_admin ---
[INFO] Compiling 307 source files to D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\classes
[WARNING] D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\src\main\java\de\...\services\java\util\Cryptographer.java:[34,40] BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\src\main\java\de\...\services\java\util\Cryptographer.java:[59,39] BASE64Decoder is internal proprietary API and may be removed in a future release
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # services_admin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) # services_admin ---
[INFO] Compiling 48 source files to D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # services_admin ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) # services_admin ---
[INFO] Packaging webapp
[INFO] Assembling webapp [services_admin] in [D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\src\main\webapp]
[INFO] Webapp assembled in [2328 msecs]
[INFO] Building war: D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.360 s
[INFO] Finished at: 2017-01-31T16:00:01+01:00
[INFO] Final Memory: 46M/447M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\pom.xml to services_admin/services_admin/2/services_admin-2.pom
[JENKINS] Archiving D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin.war to services_admin/services_admin/2/services_admin-2.war
channel stopped
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Deploying D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin.war to container Tomcat 7.x Remote
Redeploying [D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin.war]
Undeploying [D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin.war]
Deploying [D:\Programme_x64\Jenkins\jobs\Mavenproject - services Admin (Test)\workspace\target\services_admin.war]
Finished: SUCCESS
remoteserver log:
Feb 01, 2017 9:50:09 AM org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] log
INFORMATION: Manager: list: Listing contexts for virtual host 'localhost'
Feb 01, 2017 9:50:09 AM org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] log
INFORMATION: Manager: deploy: Deploying web application '/services'
Feb 01, 2017 9:50:09 AM org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] log
INFORMATION: Manager: Uploading WAR file to D:\Programme_x64\tomcat\...\webapps\services.war
Feb 01, 2017 9:50:15 AM org.apache.catalina.startup.HostConfig deployWAR
INFORMATION: Deploying web application archive D:\Programme_x64\tomcat\...\webapps\services.war
Feb 01, 2017 9:50:15 AM org.apache.tomcat.util.digester.Digester begin
WARNUNG: [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
Feb 01, 2017 9:50:24 AM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Feb 01, 2017 9:50:25 AM org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/services] log
INFORMATION: No Spring WebApplicationInitializer types detected on classpath
Feb 01, 2017 9:50:25 AM org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/services] log
INFORMATION: Set web app root system property: 'OsWebApp.root' = [D:\Programme_x64\tomcat\...\temp\6-services\]
Feb 01, 2017 9:50:25 AM org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/services] log
INFORMATION: Initializing Spring root WebApplicationContext
Feb 01, 2017 9:50:31 AM com.sun.faces.config.ConfigureListener contextInitialized
INFORMATION: Mojarra 2.1.13 ( 20120907-1514) für Kontext '/services' wird initialisiert.
Feb 01, 2017 9:50:32 AM com.sun.faces.spi.InjectionProviderFactory createInstance
INFORMATION: JSF1048: PostConstruct/PreDestroy-Annotationen vorhanden. Verwaltete Bean-Methoden, die mit diesen Annotationen markiert sind, lassen die entsprechenden Annotationen verarbeiten.
Feb 01, 2017 9:50:33 AM com.sun.faces.config.configprovider.BaseWebConfigResourceProvider getResources
WARNUNG: JSF1067: Ressource /WEB_INF/wickedcharts.taglib.xml, die von der Konfigurationsoption javax.faces.CONFIG_FILES angegeben wird, kann nicht gefunden werden. Die Ressource wird ignoriert.
Feb 01, 2017 9:50:33 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
INFORMATION: Running on PrimeFaces 5.3
Feb 01, 2017 9:50:33 AM org.apache.catalina.startup.HostConfig deployWAR
INFORMATION: Deployment of web application archive D:\Programme_x64\tomcat\...\webapps\services.war has finished in 17,323 ms
i dont use the "deploy plugin - deploy war/ear to a container" for this project. Instead of that im using now "Send files to a windows share - CIFS Publishers".
The problem with the "deploy plugin - deploy war/ear to a container" i could solve :(.
Anyway thx for ur help :).
Best regards

Cargo Maven Tomcat NoInitialContextException When i already got Context

i am using cargo maven plugin to deploy my .war to a Tomcat 8 instance for integration testing.
The application is a jersey-based REST webinterface.
My problem appears in the underlying database connection pooling.
In integration test, there is a NoInitialContextException leading to a NullPointerexception.
I build 2 pools (1 for the application and one for oacc):
public class DBCPool {
static final Logger LOGGER = LogManager.getRootLogger();
static DataSource dbs = null;
static DataSource oaccDS = null;
private DBCPool() {};
public static boolean startup() {
if (dbs != null && oaccDS != null) {
LOGGER.trace("DBCPool startup when pool != null");
return true;
} else {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Context ctxt = new InitialContext();
LOGGER.debug("Initial context is: " + ctxt.getNameInNamespace());
if (dbs == null) {
LOGGER.trace("GTM DBCPool startup");
dbs = (DataSource) ctxt.lookup("java:comp/env/jdbc/gtmdb");
LOGGER.trace("Set dbs as " + dbs.toString());
}
if (oaccDS == null) {
LOGGER.trace("OACC DBCPool startup");
oaccDS = (DataSource) ctxt.lookup("java:comp/env/jdbc/oaccdb");
}
return true;
} catch (Exception e) {
LOGGER.catching(e);
return false;
}
}
}
public static Connection getConnection() throws SQLException {
if (dbs == null) {
LOGGER.debug("Had to start DBCPool in getConnection.");
}
return dbs.getConnection();
}
There is some logging now which i added to understand the error, which will be deleted later.
The startup() is called on contextInitialized, therefore the DBCPool is set when the application is running.
As integration test, i've written:
#Test
public void getConnectionShouldReturnConnection() throws SQLException {
DBCPool.startup();
assertEquals(true, DBCPool.getConnection() != null);
}
The DBCPool.startup() is unnecessary for the test, but helps here because it brings the underlying Exception to the log in cli.
I then use cargo maven plugin to deploy this to a tomcat 8 instance and failsafe to do the integration testing.
This is the pom.xml snippet:
<profile>
<id>run-its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>failsafe-it</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
</container>
<configuration>
<home>${project.build.directory}/catalina-base</home>
</configuration>
</configuration>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
The tomcat is started and the application is deployed.
Then even the DBCPool is set up and i get no NullPointerException when logging the toString() of the datasource. This is the startup log, the log4j part cut out because it got too long.
[INFO] --- cargo-maven2-plugin:1.5.0:start (start-server) # gtm ---
[INFO] [2.ContainerStartMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-tomcat:jar:1.5.0 for container tomcat8x
[INFO] You did not specify a container home nor any installer. CARGO will automatically download your container's binaries from [http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.0.35/tomcat-8.0.35.zip].
[INFO] [talledLocalContainer] Tomcat 8.x starting...
[INFO] [stalledLocalDeployer] Deploying [C:\Users\timki\git\gtm-code\gtm\target\gtm.war] to [C:\Users\timki\git\gtm-code\gtm\target/catalina-base/webapps]...
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:35 AM org.apache.catalina.startup.VersionLoggerListener log
[...]
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:35 AM org.apache.catalina.startup.HostConfig deployWAR
[INFO] [talledLocalContainer] INFORMATION: Deploying web application archive C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\gtm.war
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[WARNING] [talledLocalContainer] WARNUNG: Name = oaccdb Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "50" for "maxActive" property, which is being ignored.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[WARNING] [talledLocalContainer] WARNUNG: Name = oaccdb Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "5000" for "maxWait" property, which is being ignored.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[WARNING] [talledLocalContainer] WARNUNG: Name = gtmLog Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "30" for "maxActive" property, which is being ignored.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[WARNING] [talledLocalContainer] WARNUNG: Name = gtmLog Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "5000" for "maxWait" property, which is being ignored.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[WARNING] [talledLocalContainer] WARNUNG: Name = gtmdb Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "50" for "maxActive" property, which is being ignored.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[WARNING] [talledLocalContainer] WARNUNG: Name = gtmdb Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "5000" for "maxWait" property, which is being ignored.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:36 AM org.apache.jasper.servlet.TldScanner scanJars
[INFO] [talledLocalContainer] INFORMATION: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,164 localhost-startStop-1 DEBUG Initializing configuration XmlConfiguration[location=C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\gtm\WEB-INF\classes\log4j2.xml]
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,171 localhost-startStop-1 DEBUG Installed script engines
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,440 localhost-startStop-1 DEBUG Oracle Nashorn Version: 1.8.0_73, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,441 localhost-startStop-1 DEBUG PluginManager 'Core' found 99 plugins
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,441 localhost-startStop-1 DEBUG PluginManager 'Level' found 0 plugins
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,445 localhost-startStop-1 DEBUG No scheduled items
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,445 localhost-startStop-1 DEBUG PluginManager 'Lookup' found 13 plugins
[INFO] [talledLocalContainer] 2016-07-17 10:07:37,447 localhost-startStop-1 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
[...]
[INFO] [talledLocalContainer] 10:07:37.558 [localhost-startStop-1] INFO - GTM servlet context initialized
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] DEBUG - Initial context is: java:
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] TRACE - GTM DBCPool startup
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] TRACE - Set dbs as org.apache.tomcat.dbcp.dbcp2.BasicDataSource#79270e48
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] TRACE - OACC DBCPool startup
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:37 AM com.sun.jersey.api.core.PackagesResourceConfig init
[INFO] [talledLocalContainer] INFORMATION: Scanning for root resource and provider classes in the packages:
[INFO] [talledLocalContainer] de.osg.gtm.web
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:37 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
[INFO] [talledLocalContainer] INFORMATION: Root resource classes found:
[INFO] [talledLocalContainer] class de.osg.gtm.web.FrontendService
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:37 AM com.sun.jersey.api.core.ScanningResourceConfig init
[INFO] [talledLocalContainer] INFORMATION: No provider classes found.
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:37 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
[INFO] [talledLocalContainer] INFORMATION: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.catalina.startup.HostConfig deployWAR
[INFO] [talledLocalContainer] INFORMATION: Deployment of web application archive C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\gtm.war has finished in 2,448 ms
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.catalina.startup.HostConfig deployDirectory
[INFO] [talledLocalContainer] INFORMATION: Deploying web application directory C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\host-manager
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.catalina.startup.HostConfig deployDirectory
[INFO] [talledLocalContainer] INFORMATION: Deployment of web application directory C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\host-manager has finished in 31 ms
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.catalina.startup.HostConfig deployDirectory
[INFO] [talledLocalContainer] INFORMATION: Deploying web application directory C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\manager
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.catalina.startup.HostConfig deployDirectory
[INFO] [talledLocalContainer] INFORMATION: Deployment of web application directory C:\Users\timki\git\gtm-code\gtm\target\catalina-base\webapps\manager has finished in 24 ms
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.coyote.AbstractProtocol start
[INFO] [talledLocalContainer] INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.coyote.AbstractProtocol start
[INFO] [talledLocalContainer] INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
[INFO] [talledLocalContainer] Jul 17, 2016 10:07:38 AM org.apache.catalina.startup.Catalina start
[INFO] [talledLocalContainer] INFORMATION: Server startup in 2821 ms
[INFO] [talledLocalContainer] Tomcat 8.x started on port [8080]
[INFO]
[INFO] --- maven-failsafe-plugin:2.19.1:integration-test (failsafe-it) # gtm ---
[INFO] Failsafe report directory: C:\Users\timki\git\gtm-code\gtm\target\failsafe-reports
-------------------------------------------------------
T E S T S
As you can see from
[INFO] [talledLocalContainer] 10:07:37.558 [localhost-startStop-1] INFO - GTM servlet context initialized
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] DEBUG - Initial context is: java:
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] TRACE - GTM DBCPool startup
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] TRACE - Set dbs as org.apache.tomcat.dbcp.dbcp2.BasicDataSource#79270e48
[INFO] [talledLocalContainer] 10:07:37.565 [localhost-startStop-1] TRACE - OACC DBCPool startup
I got the initialContext and even the datasource from the lookup.
But then, in testing:
10:07:39.631 [main] ERROR - Catching
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) ~[?:1.8.0_73]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313) ~[?:1.8.0_73]
at javax.naming.InitialContext.getNameInNamespace(InitialContext.java:563) ~[?:1.8.0_73]
at de.osg.gtm.management.DBCPool.startup(DBCPool.java:34) [classes/:?]
at de.osg.gtm.management.DBCPoolIT.getConnectionShouldReturnConnection(DBCPoolIT.java:13) [test-classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_73]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_73]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_73]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) [junit-4.8.2.jar:?]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) [junit-4.8.2.jar:?]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) [junit-4.8.2.jar:?]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) [junit-4.8.2.jar:?]
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) [junit-4.8.2.jar:?]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) [junit-4.8.2.jar:?]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) [junit-4.8.2.jar:?]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) [junit-4.8.2.jar:?]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) [junit-4.8.2.jar:?]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) [junit-4.8.2.jar:?]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) [junit-4.8.2.jar:?]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) [junit-4.8.2.jar:?]
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) [junit-4.8.2.jar:?]
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290) [surefire-booter-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242) [surefire-booter-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121) [surefire-booter-2.19.1.jar:2.19.1]
10:07:39.637 [main] DEBUG - Had to start DBCPool in getConnection.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.684 sec <<< FAILURE! - in de.osg.gtm.management.DBCPoolIT
getConnectionShouldReturnConnection(de.osg.gtm.management.DBCPoolIT) Time elapsed: 0.656 sec <<< ERROR!
java.lang.NullPointerException
at de.osg.gtm.management.DBCPoolIT.getConnectionShouldReturnConnection(DBCPoolIT.java:14)
So there it is. I get the DBCPool set up, but then in testing the dbs (databasesource, the DBCPool instance) is null again and initialContext can not be retrieved.
I guess i did something wrong in configuring failsafe, so that it does not test the deployed application and therefore does not get a Context. But i do not find my error, no matter how many examples and tutorials i study.
I had the same error with maven tomcat plugin and hoped to solve it with the cargo maven plugin, but no.
Thanks in advance for any help.
RMG
Have you thought about the maven lifecycle and when the cargo-maven2-plugin starts to work? Maybe the application will be deployed after the integration tests.
If the lifecycle would be like:
Maven: clean > test > it-test > install > deploy
Your it-suite would run without the necessary tomcat container. And fail with good reasons.
Maybe you split your profile run-its into:
deploy application with cargo (exclude its)
run its (exclude deployment)
This approach would ensure the up-and-running tomcat container.

Resources