Wrong war file name in deployment directory - eclipse

I am having a "404 Not found" error message when visiting at:
http://localhost:8080/bword in Eclipse.
This application is served in Wildfly. In POM.xml, it defines:
<artifactId>bword</artifactId>
<packaging>war</packaging>
<name>bword</name>
However, strange enough, when I run the application in Eclipse with Wildfly 9.0 configured as the server, what's deployed into wildfly/standone/deployments/ is bbword.war, as below:
[abigail#localhost wildfly-9.0.2.Final]$ ls standalone/deployments/
bbword.war/ bbword.war.deployed
Which is wrong, it should be "bword.war/" and "bword.war.deployed".
Outside of Eclipse, if I "mvn clean package" under the project "bword", I can get the "bword.war" under the target/ directory.
Please see the attachment screenshot for reference. I suspect somewhere in my pom, or eclipse, or whatever place, there is a misconfiguration of "bbword", instead of "bword", but I can't really find it. I can't find any trace of "bbword". What dictates the name of the deployed war file under deployments?
See attached.
Edited (Part of the POM.xml):
<build>
<!-- Set the name of the war, used as the context root when the app
is deployed -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- WildFly plugin to deploy war -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates
annotation processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
One more addition:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
17:32:35,508 INFO [org.jboss.modules] (main) JBoss Modules version 1.4.3.Final
17:32:35,702 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
17:32:35,761 INFO [org.jboss.as] (MSC service thread 1-6) WFLYSRV0049: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) starting
17:32:36,573 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 22) WFLYCTL0028: Attribute 'job-repository-type' in the resource at address '/subsystem=batch' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
17:32:36,594 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found bbword.war in deployment directory. To trigger deployment create a file called bbword.war.dodeploy
17:32:36,625 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
17:32:36,647 INFO [org.xnio] (MSC service thread 1-5) XNIO version 3.3.1.Final
......
This is the very initial section of the console message after I click "Run as Server" on Wildfly. It seems that it shows "Found bbword.war in deployment directory." Before I run it, I delete all in standalone/deployments/*. It start with an empty directory. It seems the "bbword.war" is copied to this directory whenever I run the server. I can't figure out. I use "find / -name bbword.war" on my computer but can't find this file. Really puzzled.
Update on this:
Eventually found out the problem: under the project 'bword', there is a ".setting" directory, which contains this file:
bword/.settings/org.eclipse.wst.common.component
And there is a line in it: , where "bbword" was the previous deploy name I used. Remove this directory and in Maven, run "update" seems fixing this problem. In particular, I need to do both, first delete this dirctory, .setting, then update maven.
Several days wasted on this, but it's good to know about this.

Had the same issue and fixed it by having corrected those 2 files :
.settings/org.eclipse.wst.common.component
=>deploy-name, etc
.project
=>name

First, try deploying the maven-built artifact (bword.war) on your server(Do not forget to completely clean-up any Eclipse deployed artifacts first).
You can do this by simply moving the bword.war from your /target folder to your path_to_wildfly/standalone/deployments folder.
Check the server log file for message: Registered web context: <web_context_name> that should appear once your war is deployed.
If it says /bbword - which is not what you expect, check whether you have a jboss-web.xml file in src/main/webapp/WEB-INF that specifies this as a web-context value.
If the maven artifact results in correct webcontext - /bword, then it must be an Eclipse configuration issue. Have you tried updating the Eclipse project from Maven? :
right click on your project
select Maven
select Update Project
remove your project from Wildfly server, and add it again. If that does not help, try adding a new server runtime and add your project there. Last resort would be to create a new Eclipse workspace.
Good luck.

The listed solutions didnt work for me.
I had to create a completely new project in eclipse:
File->New->Project
named it correctly, and then copy-pasted the necessary code from the old project.
Now the server name is correct.

If you'e running from intellij idea config then checkout artifact name in project structure. I had to rename it manually after fixing finalname tag in pom.xml. Better avoid any timestamp in artifact name.

Related

Eclipse - maven - what goal should I execute to actually deploy to Wildfly from maven (achieve the same result as the "run on server" eclipse command)

New to maven - I have an eclipse project that I can Right click > Run as... > Run on server and it runs successfully on my local Wildfly installation. Is there a way to RClick> Run as... and choose an appropriate maven goal to achieve the same effect (ie package as a war, copy to the servers dir (re)staring the server) ? Do I need to use a "wildfly maven plugin" ?
Similar question for tomcat: maven deploy goal failing
I am on eclipse Luna Java EE pack, maven 3.1 (the one that comes with eclipse) and using Wildfly 8.1.0.Final
Related:
One click build and deploy using Eclipse/Maven/JBoss AS 7
EDIT: I am now on Wildfly - so I edited accordingly
The closest I got was:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<configuration>
<jbossHome>C:/_/wildfly-8.1.0.Final</jbossHome>
</configuration>
</plugin>
but I would like to avoid hardcoding the path there - how should I proceed ?
You can use jboss plugin
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
</plugin>
Then set goal as: “jboss-as:deploy clean”
It will deploy war on JBoss server.

Unable to see log output of Spring when starting Jetty from Maven plugin

I am developing a webapp in Eclipse Juno as a Maven multi-module project using Spring MVC and the Jetty Maven plugin version 8.1.7.v20120910 with HSQL as in-memory DB during development. I want to start Jetty from within the IDE using the jetty:run goal. The problem is that I cannot see any log outputs from Spring, but I suspect the context is indeed being loaded since console log outputs stop briefly - just as long as it would take to load my yet so small Spring context - before throwing an NPE on an Autowired bean. So my suspicion is that something went wrong while starting up the Spring context.
This is the log output just before it "stops" briefly:
[INFO] web.xml file = file:/F:/projects/matching/template/template-app/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = F:\projects\matching\template\template-app\src\main\webapp
2013-01-26 11:09:18.130:INFO:oejs.Server:jetty-8.1.7.v20120910
2013-01-26 11:09:20.704:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.
Which after the pause is followed by:
2013-01-26 11:09:35.884:INFO:/:No Spring WebApplicationInitializer types detected on classpath
2013-01-26 11:09:36.742:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/F:/projects/matching/template/template-app/src/main/webapp/},file:/F:/projects/matching/template/template-app/src/main/webapp/
2013-01-26 11:09:36.742:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/F:/projects/matching/template/template-app/src/main/webapp/},file:/F:/projects/matching/template/template-app/src/main/webapp/
2013-01-26 11:09:36.742:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/,file:/F:/projects/matching/template/template-app/src/main/webapp/},file:/F:/projects/matching/template/template-app/src/main/webapp/
2013-01-26 11:09:36.743:WARN:oejw.WebAppContext:Failed startup of context o.m.j.p.JettyWebAppContext{/,file:/F:/projects/matching/template/template-app/src/main/webapp/},file:/F:/projects/matching/template/template-app/src/main/webapp/
java.lang.NullPointerException
Now I am confident that I will be able to fix whatever is causing the NPE, but for that I need to see what is happening to my Spring context. I used to work on the same constellation of tools last year, when a colleague had set it up with what I believe was the same configuration as I am using now.
I have searched the web all morning and couldn't find anything useful about it, only the vague suggestion to run Jetty externally and assemble the war and deploy the app, which is exactly not what I want.
This is my pom's build configuration:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
<warName>template</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
<webApp>
<jettyEnvXml>${jettyEnvXml-file}</jettyEnvXml>
</webApp>
<contextPath>template</contextPath>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>file:jetty/log4j-jetty.properties</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
And this is my log4j configuration for Jetty:
log4j.debug=true
log4j.threshold=ALL
log4j.rootLogger=DEBUG, consoleLogger
log4j.appender.consoleLogger=org.apache.log4j.ConsoleAppender
log4j.appender.consoleLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleLogger.layout.ConversionPattern=%-5p [%t]: %m%n
log4j.appender.consoleLogger.Threshold=TRACE
Could it have to do with this line at the beginning of my log?
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
But as far as I know it's just an m2e bug that can be ignored. I have slf4j in my classpath though.
When I run my unit tests with HSQL in the SpringJPA module, it works nicely, so I suspect it's a Jetty issue or something with my log4j configuration is just bogus.
Any ideas, hints, helps are greatly appreciated.
You have slf4j in your classpath, then Jetty will use slf4j.
Make sure you setup/configure for slf4j.
You can even setup slf4j to have its log events route to log4j for actual writing to disk or presenting to your console.

jboss 7 deployment issues with war

We are using jboss 7 and the jboss-as-maven-plugin to autodeploy our war files. We have a web.xml with the contextRoot set to our application name. In the plugin we configured our fileName to be ${project.build.finalName}.${project.packaging}. It deploys fine but the issue is when our war file name changes when we change our release number.
So for example The war changes from myproject-v1.0.1.war to myproject-v1.0.2.war when we get ready to release our next version. Issue is when the maven jboss plugin runs and tries to deploy the war file. Note We have force set to true so it should un-deploy the old application and deploy the new one.
The issue is it seems to key off of the war file name and not the webContext when determine if the application is currently deployed. So the new version fails to deploy because the old one is still running. We have to go in and manually un-deploy the previous version then re-depoly. It seems that the force un-deploy of the old app is based on the war name and since the version number changes it doesn't think its deployed and leaves the old version running. Which cause it to fail because the webContext is already used.
We attempted to change the config in the plugin to be generic and that works (the runtime name and name show this name and no longer the war file name). But the only issue is that seems to affect something on jboss and though it says its deployed the webContext isn't valid and we can't get to our application. Which is stranges since the webContext is set in the web.xml but it seems that the config in the plugin some how breaks it.
There is a name configuration attribute you can define. That should override the deployment name. If it's not set it does use the name of the file.
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.3.Final</version>
<configuration>
<name>your-app</name>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
So after playing with this for a while, we couldn't find any reason as to why when we used the config it would deploy but the webContext was not set. But when we manually deployed the same WAR it set the webContext.
So in the end. What we ended up doing was changing the name of the war to a generic name. So rather then myapp_v_1_0_1.war we made it myapp.war. This is a pain because now we don't know what version is deployed by just looking in the console. We need to hit the application which display the version number. But by doing this it solved our issue with un-deploying the old app, but created a new issue where its not as easy to determine the version deployed via the console.
This article seems to answer your question.
https://community.jboss.org/wiki/HowdoIoverridethewebcontextroot
I tried it on my own project and it works! Basically, create a jboss-web.xml (now your project is specific, so much for write once deploy anywhere). Make the jboss-web.xml look like...
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/rmbMavenCounter</context-root>
</jboss-web>
Remove the configuration from the pom.xml for the jboss-as-plugin. My plugin now looks like
<build>
<plugins>
.....
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
</plugin>
</plugins>
</build>
It will deploy with the snapshot name in the jboss admin console, but you can use the text string to access your application. For example, I used the following link to access the above application.
http://localhost:8080/rmbMavenCounter/
Here is the deployment from my jboss web server console...
08:12:42,413 INFO [org.jboss.as.server.deployment] (MSC service thread 1-16) JBAS015876: Starting deployment of "mavenCounter2-0.0.1-SNAPSHOT.war"
08:12:42,606 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Initializing Mojarra 2.1.5 (SNAPSHOT 20111202) for context '/rmbMavenCounter'
08:12:42,663 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Monitoring jndi:/default-host/rmbMavenCounter/WEB-INF/faces-config.xml for modifications
08:12:42,665 INFO [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /rmbMavenCounter
08:12:42,678 INFO [org.jboss.as.server] (management-handler-threads - 30) JBAS018559: Deployed "mavenCounter2-0.0.1-SNAPSHOT.war"
Same problem I faced: I wanted to upload the war using the version and build number for easy identification but at the same time to overwrite the previous service based on its name (with no version/build number).
This seems to be a limitation in the maven Jboss plugin: http://docs.jboss.org/jbossas/7/plugins/maven/latest/deploy-mojo.html. Currently only the 'name' parameter is supported which overwrites both the Name and the Runtime Name in the JBoss management console.
I would say long-term the plugin needs to support the 'runtimeName' as well in the list of parameters to the maven 'deploy' goal.
What you can do though, is to undeploy the service first using the 'undeploy' goal and use the 'matchPattern' parameter to find you previous service even if it included the version/build name.
Of course the disadvantage is that you have to undeploy; which is not well suited for a production environment.
For you example:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<port>${JBOSS_PORT}</port>
<username>${JBOSS_USERNAME}</username>
<password>${JBOSS_PASSWORD}</password>
<force>true</force>
<ignoreMissingDeployment>true</ignoreMissingDeployment>
</configuration>
<executions>
<execution>
<id>undeploy-MyProject</id>
<phase>install</phase>
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<hostname>${HOSTNAME}</hostname>
<matchPattern>myproject.*\.war</matchPattern>
</configuration>
</execution>
<execution>
<id>deploy-MyProject</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<hostname>${HOSTNAME}</hostname>
<name>myproject-${project.version}.war</name>
<filename>target/myproject-${project.version}.war</filename>
</configuration>
</execution>
</executions>
</plugin>

Run WAR file in /target directory of Maven project by Tomcat

I'm developing a web application with Java and Maven build system and the web server is Tomcat 7.0.12. After packaging whole project to a WAR file to \target directory by Maven build command, I have to copy it to the webapps folder of Tomcat home to run it. It's very inconvenient, especially when I modified some source files because I have to do all those things (build, copy to Tomcat, run it) again. I've research some articles about Maven, Tomcat, Eclipse on this problem, but there's no result.
Could you please help me:
1. How to make Tomcat run the WAR file on target directory of project which is built by Maven command directly? No need to copy/paste the WAR file and restart Tomcat?
2. How can I configure the Tomcat to debug the web application on Eclipse?
Thank you so much!
BTW, I've read and tried to configure Tomcat, Maven and pom file many times. But I don't know what is the exact configuration, because there are so many advices! Could you provide a particular example of configuration for me?
Here is my configuration files:
Tomcat tomcat-users.xml
<role rolename="manager-gui"/>
<user username="admin" password="" roles="manager-gui"/>
**<role rolename="manager"/>
<user username="admin" password="" roles="manager"/>**
<role rolename="admin-gui"/>
<user username="admin" password="" roles="admin-gui"/>
Maven settings.xml
tomcat
admin
And the pom.xml file of project:
<build>
<finalName>my-project</finalName>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<server>tomcat</server>
<warFile> ${project.build.directory}/${project.build.finalName}.war</warFile>
</configuration>
</plugin>
</plugins>
// Other plugins
</build>
More details:
If I run mvn tomcat:deploy before starting a Tomcat instance, the returned error is "Cannot invoke Tomcat manager: Connection refused: connect."
Otherwise, if a Tomcat instance has been started before calling mvn tomcat:deploy, the error is "Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fmy-project&war=..."
There are a couple of ways to do this.
The tomcat maven plugin http://mojo.codehaus.org/tomcat-maven-plugin/ provides you a way to deploy directly to tomcat from maven. You must have configured your tomcat users first. See http://tomcat.apache.org/tomcat-7.0-doc/config/realm.html for instructions on how to configure your users.
For debugging you can start tomcat with the arguments specified at http://wiki.apache.org/tomcat/FAQ/Developing
The other way would be to configure tomcat to point to your war. See http://tomcat.apache.org/tomcat-7.0-doc/config/context.html particularly the docbase parameter.
EDIT 1
Based on the revised question http 403 is a forbidden this means you didn't authenticate correctly.
Change your tomcat-users.xml to look as follows:
You need to add a refrence to the username/password in your pom.xml.
You settings.xml must contain (based on your configuration)
<server>
<id>tomcat</id>
<username>admin</username>
<password></password>
</server>
Theres a good page http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html that explains it more fully. However the information may be out of date.
I ran into exactly the same issue.
I suppose it is eclipse-tomcat plugin that is doing this. And I have no idea why it works differently in tomcat 7 opposed to tomcat 6 which I didn't have problem with.
Anyways, what I did was to have maven build into the /web-app/WEB-INF directory
<build>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
...
</build>
After this config, eclipse:eclipse should yield a proper eclipse project/classpath files
resources:resources shoudl work accordingly as well.

Can I make a WAR depend on a JNDI entry in JBoss 5.1?

As part of an upgrade from JBoss 4.0.4 to 5.1, I am trying to get a WAR to deploy after an EAR is successfully deployed. JBoss 5.x does not support PrefixDeploymentSorter like 4.x did, which means that I have to use <depends> in the WAR's jboss-web.xml.
It seems I cannot depend on the EAR itself, so I pick the last deployed EJB instead. This EJB provides a JNDI entry that the WAR needs.
Here's the EJB as it deploys when the WAR is absent from the deploy directory:
2010-03-25 10:47:30,348 INFO [org.jboss.ejb3.session.SessionSpecContainer] (main) Starting jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3
2010-03-25 10:47:30,350 INFO [org.jboss.ejb3.EJBContainer] (main) STARTED EJB: my.package.MyFacadeBean ejbName: MyFacadeBean
2010-03-25 10:47:30,371 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (main) Binding the following Entries in Global JNDI:
my/MyFacade/local - EJB3.x Default Local Business Interface
my-ear/MyFacadeBean/local-my.package.MyFacade - EJB3.x Local Business Interface
And here's the depends snippet from jboss-web.xml:
<depends>jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3</depends>
My problem is: The WAR starts to deploy immediately after "STARTED EJB:", i.e. before MyFacadeBean is bound to JNDI, which causes bean deployments to fail:
2010-03-25 10:47:39,068 ERROR [my.facade.FacadeFactory] (main) MyFacade not bound
2010-03-25 10:47:39,069 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[my.host.no].[/]] (main) StandardWrapper.Throwable
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at my.freemarker.servlet.FreemarkerController.setupPojoServiceFactory(FreemarkerController.java:621)
[...]
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: MyFacade not bound
at my.facade.FacadeFactory.getFacade(FacadeFactory.java:61)
After the WAR has finished its deployment, MyFacade happily (mockingly?) continues its deployment and binds the JNDI entries.
If I hot-deploy the WAR after the EAR has deployed, everything works as intended.
I even thought of depending on a dummy EJB in the EAR, and using <module-order>strict</module-order> in jboss-app.xml to force it to load as the last module. But alas, JBoss 5.x does not support that either. Doh!
Is there a way to depend on the JNDI entry itself? Are there other ways of solving this?
Here's how you can achieve this on JBoss 5.1.x.
First, add a file called aliases.txt into the META-INF directory of your EAR. This file should just contain a single line with an arbitrary name / identifier for your EAR. For example, if you have my-ear.ear, your META-INF/aliases.txt file could contain 'my-ear'. It just needs to be something that won't clash with any other aliases declared by other apps deployed on the same server.
Next, add a jboss-dependency.xml file to the META-INF directory of your WAR, containing the following (subsituting 'my-ear' for the alias you created above):
<dependency xmlns="urn:jboss:dependency:1.0">
<item whenRequired="Real" dependentState="Create">my-ear</item>
</dependency>
This will ensure the EAR is deployed before the WAR.
Also, if you try to deploy the WAR without the EAR being present, JBoss will log a clear deployment error message telling you about the missing dependency.