English 中文(简体)
Net Beans Maven{tomcat_base}/bin rafter as false sectionpath
原标题:NetBeans Maven {tomcat_base}/bin folder as false classpath

I m在Net Beans 7.1.1开发一个Maven网,Apache Tomcat 7.0.22作为服务器。 Java课在运行或铺设时,将“家庭/用户/用户/用户-原子-7.0.22/bin/”作为档案的基础。

例如,如果创立一个新档案,名为“Writer rssFile = 新的卷宗(“测试.xml”),则该新档案是“/home/user/apache-tomcat-7.0.22/bin/test.xml”。

在查找图像或其他档案时,也出现了同样的问题。 它开始搜索“家庭/用户/用户/用户-原子-7.0.22/bin”。

项目档案不是在Tomcat基地,因此我不知道为什么把双倍夹作为等级的基础......。 在编码客户方面(ex. *.jsp),找到了正确的道路,但不是在服务器边代码(Java级)中。

This problem is the same mentioned by other user in https://stackoverflow.com/questions/7774446/netbeans-setting-default-current-directory-for-tomcat , but none solutions were given.

这可能与Net Beans Maven plugin混在一起。 如何解决这一问题?

问题回答

如果你与使用Tomcat重新挂钩,你可以利用两种系统特性:

  • catalina.home - Where tomcat is installed (/home/user/apache-tomcat-7.0.22)
  • catalina.base - Where a tomcat instance is based (typically the same as above, but can be configured to allow multiple Tomcat instances to be run all based from the same common binaries)

因此,你可以使用:

new File(System.getProperty("catalina.base") + "/conf/test.xml");

如果你试图把资源装入你的战争,那么,你要把资源装上集装箱是独立的:

  • 如果资源载于<条码>WEB-INF/classes 夹,请将资源装上“InputStreams”,使用:

    Classloader.getResourceAsStream("/test.xml");
    
  • If you re using 2.5 servlet spec or beyond, and you have access to the ServletContext (or HttpServletRequest or HttpSession from which you can drill down to acquire the ServletContext):

    ServletContext.getRealPath("/"); // will return the root of your web app
    




相关问题
Tomcat´s server.xml dynamic configuration

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

热门标签