Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Weblogic (12 C) without the application context in the URL?

I am working on a web project that requires Weblogic server and the only way I can view the site after deploying (on my Macbook Pro) is by specifying the application name as a prefix to the entire site. E.g.

http://localhost:7001/myapp-weblogic/

This breaks a ton of styling and JavaScript code that access resources with root URLs (e.g. /images/example.png)

While I can programmatically add "/my-app" to content in a .jsp, I can't do that in my .css files.

I tried setting the "Default WebApp Context Root:" in Weblogic > console > Environment > Servers > myserver > Protocols > HTTP - But that did not work.

This seems like it should be such a simple thing. In IIS I would simply add a line to my local hosts file and add the host name to my IIS container - taking me a grand total of about 42 seconds.

127.0.0.1   myapp.local  -> Let's me view my site at http://myapp.local

Thank you in advance for any insight!


UPDATE!! I finally got things working. Some of this is very specific to my setup, but hopefully still helpful to others.

To get it working I needed to do 3 main things and one other related thing:

  1. Set the default application for the server in Weblogic
    1. On your local server, go to the console and log in
    2. Go to: Weblogic > console > Environment > Servers > myserver > Protocols > HTTP
    3. Set the "Default WebApp Context Root:" to "/" + your application (e.g. "/myapp")
  2. Set the context-root of the project in MyEclipse
    1. With your project open in MyEclipse, right-click on the project and select properties
    2. Expand "MyEclipse" and choose "Web" and set the Web Context-root to "/"
  3. Set the value of context-root in the project weblogic.xml file to "/"
    1. This file should be located in the WEB-INF folder of your project
    2. Save the file and build the app
    3. Redeploy your app - you may need to restart your server too

Setting my local path variable to "/"

So another thing I had to do was set a path variable i was referencing to "/". When you request the path (request.getContextPath(); ) it does not prepend the path with a "/" and if you try to use something like <c:url context="${ _path }" if the the _path variable does not begin with a "/" it will throw an exception.

That last bit was something I encountered from working with someone else's code.

like image 800
Sirius_B Avatar asked Apr 05 '13 21:04

Sirius_B


2 Answers

In application.xml specify the below setting

       <web>
          <web-uri>yourweb.war</web-uri>
          <context-root>/</context-root>
       </web>

Now you can make a call without context root as

        http://localhost:7001/
like image 193
VKPRO Avatar answered Sep 21 '22 17:09

VKPRO


I assume because you are using weblogic you deploy a java application.

The structure should be a 'war' file.

More info on the structure you can find here.

http://www.openscope.net/2010/01/25/war-deployment-file-structure/

The name of the context root (by default name of the war) might be as well overridden

https://forums.oracle.com/forums/thread.jspa?messageID=10366462

Hope it helps.

like image 28
Cris Avatar answered Sep 20 '22 17:09

Cris