How do I change the context path of my Enterprise Project - netbeans

So my enterprise project name TestProject, which contain TestProject-ejb and TestProject-war, so when I run the project the url is like this locahost:8080/TestProject-war. How can I change this url to localhost:8080/testproject. I use netbean 6.9, I try to right click on TestProject-war folder in netbean, and specify the context-path there under Run, but it still load locahost:8080/TestProject-war

You need to check that the context-root element for the web module in the application.xml file that's in the META-INF directory of your EAR has been correctly changed.
An example would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
id="Application_ID" version="6">
<display-name>TestProject</display-name>
<module>
<web>
<web-uri>TestProjectWeb.war</web-uri>
<context-root>testproject</context-root>
</web>
</module>
<module>
<ejb>TestProjectEJB.jar</ejb>
</module>
</application>
In this example the web module should be available under /testproject of the server you deploy to, so in your case http://localhost:8080/testproject.
(In case you would like to deploy to the root of your server, you can leave the context-root element empty: <context-root></context-root>.)
If you indeed see that your action in Netbeans has correctly changed this file, it may be a deployment problem like BalusC indicated. Check the location the EAR is deployed to and manually inspect whether the deployed version also has the correct value.

As Harry pointed out the default project template doesn't create an application.xml file, so you have to create it by hand at $ENTERPRISE_APP_PATH/src/conf (tested with NB 6.9.1)

Just ran into this question in the course of figuring out the same thing. Since the OP was asking about doing this in Netbeans, let me add to previous answers by describing specifically how to do this using the Netbeans IDE.
With Netbeans 8 (and possibly also with earlier versions) you can tell the IDE to create the application.xml file for you, as follows. Right-click the enterprise application project (in the OP's example this would be "TestProject"), select "New" then "Standard Deployment Descriptor...". This will create an "application.xml" file and put it in the appropriate place in your Netbeans project. Then you can easily edit this file to set the context-root element to be whatever you want.

Related

Deployment of webapp in wildfly using Context Descriptors

I searched using "How to set Context Path in Wildfly", but got no success. Can anyone help me on how to do it..?
I've used the following code to set the Context Path in tomcat where I can access my application directly using localhost:8080/myApp
myApp.xml contains as follows and placed at $CATALINA_BASE\conf\[enginename]\[hostname]\myApp.xml
<Context path="myApp" docBase="G:\workspace\j2ee\myProject\myWebApp\WebContent" />
similar or equivalent type of configuration want to use in Wildfly server.
In your standalone.xml configuration you want to add a deployment like this:
<deployments>
<deployment name="myProject" runtime-name="myProject.war">
<fs-archive path="G:/workspace/j2ee/myProject/myWebApp/WebContent"/>
</deployment>
</deployments>
Then within WebContent/WEB-INF create a file called jboss-web.xml with a configuration similar to:
<?xml version="1.0"?>
<jboss-web>
<context-root>/my-context-path</context-root>
</jboss-web>
If this doesn't work you may need to rename WebContent directory to WebContent.war, even if it is exploded it may want .war in the name.

Wildfly in Eclipse is adding the Maven SNAPSHOT to the web context

I'm having a new problem when we moved to a Wildfly 8.x server in eclipse.
My project is called PayloadSvc. The first part of the pom.xml looks like this:
<modelVersion>4.0.0</modelVersion>
<groupId>PayloadSvc</groupId>
<artifactId>PayloadSvc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
Later in the pom I have this:
<build>
<finalName>PayloadSvc</finalName>
In eclipse I also have my context root in the Web Project Settings set to PayloadSvc
However, when it deploys into Wildfly it deploys this way:
Registered web context: /PayloadSvc-0.0.1-SNAPSHOT
I can't seem to get it to remove the "-0.0.1-SNAPSHOT" part of the web context.
Oddly enough, other projects in the same workplace work correctly even with the same pom data (with appropriate context, groupId, artifact Id, and the same version attribute of course).
I'm using the STS version of Eclipse Neon.
Thank you for any advice you may have.
Just had the same problem solved.
If you don't have it already, create a WEB-INF\jboss-web.xml file, with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>PayloadSvc</context-root>
</jboss-web>
Republish the resource and you're done.
Not sure why the file is not created automatically though.
Edit the file \[root-of-your-project]\.settings\org.eclipse.wst.common.component, changing the deploy-name attribute and context-root value.
Show the server tab by: Window > Show View > Server
Right click on your server then Add and Remove.... Remove all projects from server.
Right click on your server and clean.
Just to be sure, go to the directory where WildFly is installed and delete the content of the directory [wildfly-path]\[standalone-path]\deployments, if it exits.
Add again the projects into your server and run.
Have you tried adding the <name>PayloadSvc</name> element in the root of the pom (same spot as your group,artifact,version elements)?
If that doesn't help, what does the artifact look like when you build it with mvn install? Does it include the version number in the war filename?
For Eclipse Neon:
1 Did a Eclipse Neon 'Check for updates' and updated it.
2 I editted file org.eclipse.wst.common.component adding a blank line and saved (check if deploy-name is suffixed with SNAPSHOT).
3 After that the suffix '0.0.1-SNAPSHOT' disappear from the war name when adding it to Wildfly server.

How can I deploy a war-file to a subdirectory of my JBoss server?

this has got to be a stupid question but my Google-fu fails me. I have a JBoss server (actually EAP 6.1) and a packaged web application, myapp.war.
By copying the file to .../standalone/deployments/ it gets deployed to <server>/myapp. Renaming the file to somename.war, it becomes <server>/somename, and ROOT.war gets deployed directly on <server.
So far so good.
But how do I get the application to appear under e.g. <server>/antares/myapp?
I tried simply making a subdirectory under deployments/ and placing my war file there, but that still gets deployed simply as <server>/myapp. I also read somewhere on a Tomcat forum to call my file antares#myapp.war, but that resulted in an error when the deployment scanner tried to run it.
Searching around on the web, I so far mostly found (a) descriptions of the folder and subfolder structure of a web project or (b) things about projects and sub-projects and how to handle dependencies.
I don't need all of that, I just want my perfectly fine war file to show up with a slightly deeper path. Preferably without having to touch many configuration files.
What am I missing?
You need to wrap your .war in to a .ear and add the following information in to the application.xml in order to achieve what you want.
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>Your App name</display-name>
<module>
<ejb>a-ejb-module-if-you-have-one.jar</ejb>
</module>
<module>
<web>
<web-uri>myapp.war</web-uri>
<context-root>antares/myapp</context-root>
</web>
</module>
</application>
Please take a look at the documentation here: Setting the context root of a web application

RAD not adding an EAR project to a WAS instance

In my RAD workspace, I have an EAR project. Now I have a WAS 6.1 instance which i created from inside RAD. When I right click the WAS 6.1 instance and do 'Add Remove projects' and select the EAR, I get error:
Cannot add an EAR project to the server unless it contains a Web, EJB, or Connector module.
Now this is not true because in my EAR project there is META-INF/application.xml and it has the contents:
<?xml version="1.0" encoding="UTF-8"?>
<application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>
someEAR</display-name>
<module id="EjbModule_1291759813449">
<ejb>someEJB.jar</ejb>
</module>
<module>
<web>
<web-uri>someWeb.war</web-uri>
<context-root>someWeb</context-root>
</web>
</module>
</application>
So clearly it has a <web> and <ejb> module. Why is RAD complaining?
A couple of potential solutions:
Uninstall your application, stop the server, reinstall your application, start the server.
right click on the EAR and check "Deployment Assembly" and make sure your modules are being exported. if so, it is a good idea to remove them and re add them.
Check "Project References" and make sure they are checked.
To add the project back to the server,
Right click on your jar project and go to properties, click Java EE module dependencies. Select the project jar checkboxes under Available Java EE modules.
This will get the project back.
Now right click on your was server and try add/remove project. It will appear in the left panel for selection.
In my case the solution was:
1-Make sure the web project had already run Maven so as to have the .war inside Target.
2-Right click on ear project, go to Properties > Deployment Assembly.
3-Click “Add” button, choose Archives from Workspaces. Click Add, and choose your war.
4-The War now is at Deployment Assembly list.
5-Start server.
In my case I went to "Project Facets" first uncheck Dynamic web module and applied the changes. Again I selected the Dynamic web module. This helped to replace the corrupted war file and resolved the issue.

how to change Jboss default page to the home page of my application?

I have an application deployed in JBOSS and it is accessed as: localhost/appname
When i enter only the IP address i get redirected to the JBOSS default page.
Is there a way to go to the application's homepage with no need to give /appname ?
I hope the question is clear.
Thanks in advance.
A part of the solution given by Nightsorrow, you can also define the context root of your web application using the context-root tag of the WEB-INF/jboss-web.xml file. So defining it as '/', you can keep your original file name. This way you override the default behaviour of JBoss, which is defining the context root of web apps as the file name of the application (unless the app name is ROOT.war, which its default context is '/').
So the jboss-web.xml file would look like something similar to:
<jboss-web>
... other tags ...
<context-root>/</context-root>
... other tags ...
</jboss-web>
Notice that there can't be two applications with the same context root, so first you will have to remove ROOT.war, or change its context root following the same procedure:
adding the context-root tag to jboss-web.xml (for example: <context-root>/oldRoot</context-root>, which would make the old ROOT.war application available through localhost/oldRoot),or
just changing its file name.
In case you want to deploy an EAR file with a web module (war) inside (instead of just a plain war file), you've to use the META-INF/application.xml of the EAR. Defining the web module this way:
<application>
... other tags and other modules (ejb, web ...) ...
<module>
<web>
<web-uri>nameOfYourWarFile.war</web-uri>
<context-root>/</context-root>
</web>
</module>
... other tags and other modules (ejb, web ...) ...
</application>
You have to deploy your application in file named "ROOT.war". Also you have to delete existing ROOT.war in deploy directory.
I am using eap6. This is my first time to use jboss. I don't see that I have $JBOSS_HOME/server. I see $JBOSS_HOME/domain/server. I have searched all the files under $JBOSS_HOME. I cannot find any WEB-INF and jboss-web.xml