play2war / play2-war-plugin

WAR Plugin for Play framework 2.x
Apache License 2.0
443 stars 71 forks source link

Error during deployment at sub-context path in tomcat7 #295

Closed GaurangaDasa closed 8 years ago

GaurangaDasa commented 8 years ago

Hi, I am able to successfully deploy the war file at root-context path by renaming the war file to ROOT.war, but for deploying the war file to sub-context path, I rename the war file to my-app.war. The app is getting deployed to tomcat 7. The home page of app is accessible at http://xxx/my-app. But, when I navigate to another page by clicking some button, the url changes to http://xxx/newpage. Here, my-app is not there, so page is not getting displayed. I have to manually change the url to http://xxx/my-app/newpage to see the new page.

Is this fault of developer that he is not using relative paths of navigation to other pages while coding? Or I am missing any configuration? I also tried to set "application.context=/my-app/" in application.conf file but to no use.

Any help would be very useful. Thank you.

PS: Play2war version:- 1.2-beta1 Play version:- 2.2.6

dlecan commented 8 years ago

Can you show some code where a link to http://xxx/newpage is built ?

GaurangaDasa commented 8 years ago

Hi,

Following is a code snippet which navigates to page http://xxx/Reportees/id, when it should navigate to http://xxx/my-app/Reportees/id.

            <a href="/Reportees/@mgr.id"><img src="/assets/images/@mgr.id@(".png")" alt="alt text" height="170" width="170" border="1"/></a>
            <a href="/Reportees/@mgr.id"><h3>@mgr.name</h3></a>
            @mgr.current_project<br/>
            @mgr.email<br/>
            @mgr.contact_number<br/>
            @mgr.location<br/>
GaurangaDasa commented 8 years ago

I guess there's a bug in play2war plugin regarding deployment at sub-context path. Is it?

dlecan commented 8 years ago

No, if you want to host your Play application behind a reverse-proxy which adds a root-context, your links will be wrong too.

You should not use this syntax:

<a href="/Reportees/@mgr.id"><img src="/assets/images/@mgr.id@(".png")" alt="alt text" height="170" width="170" border="1"/></a>

If you have:

GET   /Reportees/:id          controllers.Reportees.show(id: Long)  

and a war file named my-root-context.war

This one is much better:

<a href="@routes.Reportees.show(mgr.id)">...</a>

It will automagically generate to following HTML:

<a href="/my-root-context/Reportees/10">...</a>

https://www.playframework.com/documentation/2.2.x/JavaRouting#Reverse-routing

Same thing for "assets", there is a reverse-route for it: https://www.playframework.com/documentation/2.2.x/Assets#The-Assets-controller

GaurangaDasa commented 8 years ago

Hi, thanks for replying.

My code is working just fine when run directly in inbuilt server of play framework, but for creating the war file and running the app, my code needs to be changed in some way. That can't be right. Your plugin needs to handle deployment to sub-context level without any changes to my code. Would you agree?

dlecan commented 8 years ago

Your plugin needs to handle deployment to sub-context level without any changes to my code. Would you agree?

No, I don't agree. War packaging is not supported by Play framework. This is a community effort to help developers and ops to migrate from legacy "application server model" to a container-less model.

If you don't want to use features provided by Play itself, such as reverse-routing which solves your problem, Play2Way can't do anything for you. It can't convert static html code to something else.

You can also deploy your war without root-context, your actual links will be ok. Please read again deployment documentation: https://github.com/play2war/play2-war-plugin/wiki/Deployment

GaurangaDasa commented 8 years ago

Okay, thanks Damien for you replies and for the plugin.