I need a little help changing the context root of my war in my Websphere 8.5 appserver.
I have a war file called test.war When I deploy it to websphere the context root is /test
However I want to change this to be /example
When I looked online I read I need to include WEB-INF/ibm-web-ext.xml within test.war so I added that and enter the following:
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<context-root uri="/example"/>
</web-ext>
When I deploy again the context-root is still /test That file has had no effect.
Is there something I am missing?
The easiest way after installation, is to open web admin console and change the context-root via:
Applications > Application Types > WebSphere enterprise applications > application_name > Context root for web modules.
You could do it also via wsadmin script.
You can provide context name, during application installation via admin console or you can change file name before installation as default context, when you install war is taken from the file name.
The last option would be to create EAR and define application.xml with web module like this:
<web>
<web-uri>test.war</web-uri>
<context-root>example</context-root>
</web>
"When I deploy again"
Did you perform an update, or an uninstall & reinstall?
When you update an application, WebSphere doesn't necessarily update the existing application's bindings (you need to explicitly ask WebSphere to discard binding information during an update). You have to select "Use new bindings" during installation in order to force WebSphere to pick up the bindings changes.
When you uninstall an application, all bindings information is lost, so when you re-install the same application, the bindings information included within the WAR file is used.
Related
https://www.pegaxchange.com/2018/01/24/java-web-project-with-spring-framework/ has instructions for creating a Java Web Project with Spring, without Maven. I am able to get it working in an Eclipse environment. It works as expected by doing “Run As” --> “Run on Server”.
When I kill Eclipse I get the Status 404 error (“The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.”). I have verified that the Tomcat Server is running from the XAMPP Control Panel.
How do I launch the application from an OS shell (Windows & Linux) so that I don't see the 404 error?
Its been a long time I haven't used java web projects without maven but if my memory serves me right, you should first export your project as .war file. Then deploy it to tomcat.
In eclipse right click your project select export and then select WAR file.
Copy your WAR file into webapps directory which is located in tomcat installation directory.
Rename the WAR file as you like if you want to serve you web app with a specific context name something like http://localhost:8080/myapp. If you do want to serve as root without a context name just rename it as "ROOT".
Run tomcat by command line <your-tomcat-installation-dir>\bin\startup.sh or it will be a .bat file for windows so you should end your command with .bat.
Or if you can start and stop by XAMPP panel this should do the same as well.
Also you can see this article for details on how to deploy a war file to tomcat.
I hope this helps. Cheers!
I try to deploy a JAVA application on Liberty (I will use <> as place holder)
On Windows:
If I add my application in Eclipe with the help of the Add and Remove.. Ressource, the application runs successfully on Liberty. In \wlp\usr\servers\<ServerName>\apps a new file <MyAppName>.war.xml is created:
<dir sourceOnDisk="C:\<MyAppName>\<MyAppName>-source\src\main\webapp" targetInArchive="/"/>
On Windows:
If I create in \wlp\usr\servers\<ServerName>\apps the file <MyAppName>.war.xml manually and link it to the <MyApp>.war directory:
<dir sourceOnDisk="C:\Users\<userName>\Desktop\<MyAppName>.war" targetInArchive="/"/>
the application runs successfully.
On Linux:
I want now to deploy the same war on a Liberty server on linux. The problem is the structure of the directories- it is completely different than in Windows.
In the appl directory, there are the following subdirectories:
appl_dropins
wl_config
Where do I have to put the file <MyAppName>.war.xml? And the server.xml? Why is so different on Linux?
On Windows the structure was for the <ServerName> apps, dropins, logs,resources, tranlog, workarea + the File server.xml
Thank you in advance.
When you deploy directly from Eclipse it is pointing to the workspace by default, which is good for development, but not for deployment to other environments.
You have following options:
change publishing options in Eclipse to publish war by unchecking 'Run applications directly from workspace'
Export application from Eclipse using Export > War file
or create packaged server - right click on your server select Utilities > Package server and then use 'usr' option.
Packed server option is quite good for moving between environments, as it gathers all - application, server.xml, and any other files you had in the server folder. Then you just unzip archive on your target host and run the server.
As Alasdair said there is no difference in directory structure between Win and Linux, so either you have some different product on Linux, or it was heavily customized by someone or some tool.
Thank you for the fast answer.
I did as you said. I created the war <MyAppNewName.war> file, unzip it <MyAppNewName> and put it in the dropings directory. When I start the server, I get among other exceptions the following one:
[ERROR ] CWWKZ0005E: The server is not configured to handle the resource at location C:\kits\wlp-webProfile7-18.0.0.1\wlp\usr\servers\newTest\dropins\<MyAppNewName>\index.xhtml.
For the App in the orginal question, the file <MyAppName>.war.xml contained
<?xml version="1.0" encoding="UTF-8"?>
<archive>
<dir sourceOnDisk="C:\Users\userName\Desktop\MyAppName.war" targetInArchive="/"/>
<dir sourceOnDisk="C:\MyAppName\MyAppName-source\target\classes" targetInArchive="/WEB-INF/classes"/>
</archive>
In C:\MyAppName\MyAppName-source\target\classes there are the .class files and the war does not contain them.
So how do I add the .classes to the war?
I have a project with Spring profile
In my web.xml, i have
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>dev</param-value>
</context-param>
to set the default spring profile.
I build the maven project with
clean install -Dspring.profiles.active="prod"
Then, I choose the option Run As -> Run on Server to deploy the maven project to tc Server.
However, the active profile is still dev.
What is the correct way to activate a spring profile on tc Server
If you are running your app from with STS and the tc Server that comes with it, you can put the system property definition into the launch configuration of tc Server. Once you started up tc Server once, you can modify the lauch config via "Run Configurations...", select the one for Pivotal tc Server, go to the VM arguments and add the -Dspring.profiles.active=prod setting.
Since this is a runtime option, it doesn't have any effect while building the app via Maven (the clean install way you tried).
Configuring Tomcat
defining context param in web.xml – that breaks “one package for all environments” statement. I don’t recommend that
defining system property -Dspring.profiles.active=your-active-profile
I believe that defining system property is much better approach. So how to define system property for Tomcat? Over the internet i could find a lot of advices like “modify catalina.sh” because you will not find any configuration file for doing stuff like that. Modifying catalina.sh is a dirty unmaintable solution. There is a better way to do that.
Just create file setenv.sh in Tomcat’s bin directory with content:
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active="prod"
and it will be loaded automatically during running catalina.sh start or run.
I don't know why the JAVA_OPTS method didn't work for me.
What does is adding spring.profiles.active=dev in /conf/catalina.properties
i have a spring mvc web application that I need to change the class loader on. I need to change the class loader to be equal to PARENT_LAST. I am using WAS 6.1 and already have a jacl script from a previous web application I can copy to do the job.
In the last application Apache ant was used and what they did was to make the deploy dependent on running the jacl script.
In my new web application I am using maven install to create a war file and am deploying that war file to my application server.
How can I set the class loader to be PARENT_LAST using maven? I know how to do it in the console but if there was a way to do it using scripting that would be nice.
Also will this setting be placed somewhere in the war file so that on deploy of the application the setting will be picked up. This question comes from my lack of understanding of how jacl scripts work?
thanks
If you are only deploying the WAR file itself you can't control this, but if you have your WAR file in an EAR file you can use the deployment.xml solution. The deployment.xml file would look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1347529484613">
<deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1347544766353" startingWeight="99" warClassLoaderPolicy="SINGLE">
<modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1347543866613" startingWeight="1" uri="YourWebApp.war" classloaderMode="PARENT_LAST"/>
<classloader xmi:id="Classloader_1347543866613" mode="PARENT_LAST"/>
</deployedObject>
</appdeployment:Deployment>
Once you are done all you need to do is to add the file in the correct location of your EAR project build assuming you are using src/main/application that would be src/main/application/META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp/deployment.xml and build the EAR using Maven as normal.
During server deployment this will be picked up by WAS.
AFAIK there is no way to preconfigure WAR for PARENT_LAST during assembly. Classloading policy is specified during deployment, thus the way of setting it depends on how application is deployed.
Changing the policy using the script is straightforward. Scripts are run using wsadmin tool. The Jython snippet below does the job. It can easily be converted to Jacl.
dep = AdminConfig.getid('/Deployment:app_name/')
depObject = AdminConfig.showAttribute(dep, 'deployedObject')
classldr = AdminConfig.showAttribute(depObject, 'classloader')
AdminConfig.modify(classldr, [['mode', 'PARENT_LAST']])
AdminConfig.save()
Websphere uses deployment.xml file to govern deployment setting of each module in an ear file. You can change the classloader setting in deployment.xml at the following path:
/MyTestEAR/META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp/deployment.xml
I do not know how you can configure that in Maven.
I have an application which uses Equinox as an osgi framework for a while now. Until now I used the system property osgi.install.area to specify where my bundles are like so
${osgi.install.area}/
plugins/
org.eclipse.osgi_3.7.0.v20110613.jar
... my app bundles
Equinox then automatically uses ${osgi.install.area}/configuration as the configuration area.
Everything works fine.
Now I need to move the configuration area out of ${osgi.install.area} because that may be read-only and I thought it was as simple as setting ${osgi.configuration.area} to a suitable path but when I do this the application no longer starts and I have the following stack trace in the logs:
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:150)
...
The path is used because at that location the log file is created and a directory "org.eclipse.osgi".
Paths to bundles are referenced in my config.ini like so:
osgi.bundles=de.mycomp.app-0.6.0.20121116-1834.jar#start, ...
The error message does not really give a hint where to look. It must be something rather simple but I am rather clueless at the moment.
Thanks in advance,
Robert
I tested changing the configuration area an existing osgi app and it worked, with the following argument below in the .ini file in the root of the install. Are you sure you are setting the config param correctly like this:
-Dosgi.configuration.area=c:\mytest
After doing that and running the app again, it created the folder and a new configuration.
Here is a copy of my .ini file that works, also it's important that osgi params come after and vm args.
-loglevel=trace
-vmargs
-Dosgi.configuration.area=c:\mytest
-Dorg.osgi.service.http.port=8094
-Declipse.ignoreApp=true
-Dosgi.noShutdown=true
-Dequinox.ds.print=true