问题
I am testing a web application(Apache Wicket Based) via IntellijIDEA Tomcat integration. There I noticed that the webapp consider its running in bin folder of the tomcat. Also when I called the ServletCotext.getContext("/") it return a null. But when I deploy them same webapp manually in tomcat it works fine. How can solve this in IntellijIDEA?
回答1:
Ok. Let's try.
1) Create IntellijIdea project via WebApplication template. Idea should be Ultimate version, not Community edition
2) Go to Run-Edit configutaion and set up Tomcat location folder, so Idea will know about your tomcat server
3) Go to Deployment tab and select Artifact. Apply
4) In src folder put your servlet (you can try my example for testing purpose)
5) Go to web.xml file and link your's servlet like this
6) In web folder put your's .jsp files (for example hey.jsp)
7) Now you can start you app via IntellijIdea. Run(Shift+F10) and enjoy your app in browser:
- to jsp files: http://localhost:8080/hey.jsp (or index.jsp by default)
- to servlets via virtual link you set in web.xml : http://localhost:8080/st
回答2:
In IntelliJ (I'm using Ultimate 2017), the context directory is set through File > Project Structure. Under the Web Resource Directories list, IntelliJ had filled in a path ending with /webapp
by default, which didn't exist and was in red. I changed that to the folder enclosing my root-level index.jsp
. After a rebuild, my JSPs were rendering and the CSS and JS (stored in the same tree as the JSPs) were loading perfectly.
来源:https://stackoverflow.com/questions/18551130/hot-to-deploy-tomcat-webapps-folder-form-intellijidea