Access external project static web resources from Struts2.5 web server

你说的曾经没有我的故事 提交于 2019-12-23 02:34:41

问题


I have some files in a lib package that I am currently working on. It needs to be used by multiple projects so I can't put the files directly within my web server.

I want my Struts2.5 web server to be able to serve some static files from my Lib package. I was looking into using a web-fragment.xml solution, but from what I gather from oracle, this is only going to work if I compile my library package and put it in my META-INF directory somewhere. That's fine and all, but really inconvenient for any sort of development or testing, as I will need to make a new build and copy it there every time I make changes to the html/js. This sounds to me like the wrong solution.

If there is a way to do this with the xml configuration, it hasn't been made clear from what I've read. If I could be pointed in the right direction, that would be helpful.

Otherwise, if there's a way to do this in Eclipse somehow that would also be acceptable. For the record, this project is referenced by the other project in eclipse as a required project in my Java Build Path.


回答1:


Put static files under Web Content Root (/). If you want Struts to serve your static content then put it under /static. Struts can also serve static content from the classpath, but it seems not an option for you.

Read my answer for Load image in jsp from different URL but same domain:

You can read more about static content loader and configuration settings in the docs for Static Content.


You can reuse the same static files from other web applications if you package and deploy static files in another .war file and specify a context path to access these files from your application. It could be served from the same domain or different domain.

You can deploy a web application with static files as web archive exploded, so you don't need to package them every time you deploy the application, and if it's a different application you don't need to redeploy other applications, unless they are affected by the access path to files.

Another approach is that you share the project with static content with other projects in Eclipse, because Eclipse copies the project files to the final .war during the building, and every web app will have its own copy of the shared files. If you want to modify some shared files, then you need to rebuild/redeploy only the project you working on. Other projects that has this project as dependency could be rebuilt/redeployed on demand. It seems most reliable solution, because modifying some web app doesn't affect other web apps running.



来源:https://stackoverflow.com/questions/44960092/access-external-project-static-web-resources-from-struts2-5-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!