裝了tomcat后發現tomcat安裝在系統跟路徑地下,每次部署的時候挺麻煩的,於是想指定一個自己定義的應用部署的路徑:
以下是如何指定,相關文檔請查看https://tomcat.apache.org/tomcat-4.1-doc/appdev/deployment.html
注意你的tomcat的版本,我在網上查的時候由於自己的版本是7.0.6,而部署的方法有幾個版本,3.1和4.1就不一樣
先講我自己的是7.0.6版本部署方式是打開tomcat的根目錄在conf文件夾底下修改server.xml文件在 最下面的</Host>標簽上面添加一個指定docBase路徑的
context flag:如
<Context path="" docBase="~/Documents/javaProject/webapps/" reloadable="true" />
注意兩個小細節:
一個是指定docBase時不要忘記了這個docBase是一個文件夾所以如上webapps后面要加上/
另外一個是docBase下要有一個WEB-INF文件夾結構里面的結構和tomcat跟目錄底下的webapps的一致。
這樣以后你的java class 和application 依賴的jar包就可以分別放在這個WEB-INF文件夾底下的class和lib下了
現在講講3.1版本的tomcat是怎么弄的:
3.1版本的tomcat也是添加context flag,但是添加的位置是在tomcatroot/conf文件夾下的apps.xml中,由於有可能這個文件夾底下沒有這個文件
這時候你需要自己創建一個這樣的文件創建完后再往里面添加
<?xml version="1.0" encoding="ISO-8859-1"?> <webapps> <Context path="" docBase="~/Documents/javaProject/webapps/" reloadable="true" /> </webapps>
這樣就好了(由於我的是7.0.6版本所以沒有試成功)
補充一下 用tomcat部署的應用可以指定的幾個屬性(都是用context flag來配置的)
path:這個是指定訪問哪個web應用用的
docBase:指定你發布的應用程序在哪里
debug:跟tomcat的log相關
reloadble:設置為true,tomcat會自動檢測你WEB-INF/class下的class文件或WEB-INF/lib中的jar包是否有新的更新,如果有的話tomcat會自動關閉並將更新加載完后重啟(大概意思是這樣的)
trusted:訪問tomcat內部類(一般情況是管理員對tomcat的操作)
翻譯都是什么鬼(見原文:)
-
- path. The context path for your application, which is the prefix of a request URI that tells Tomcat which application should be used to process this request. For example, if you set your path to "/catalog", any request URI beginning with "/catalog" will be processed by this application. This attribute is requrired, and must start with a slash ('/') character.
- docBase. The document root directory for this web application. This can be a relative path (relative to the directory in which Tomcat is started), or an absolute path, to the directory containing your app. On a Windows platform, you MUST use the drive prefix and a colon when specifying an absolute path. This attribute is required.
- debug. Debugging detail level (from "0" to "9") that defines how verbose Tomcat's logging messages will be when your application is initialized, started, and shut down. The default value is "0" (minimal logging) if you do not specify a different value.
- reloadable. Set to "true" if you want Tomcat to watch for changes to Java class files in the WEB-INF/classes directory, or JAR files in the WEB-INF/lib directory. If such a change is noted, Tomcat will shut down and reload your application automatically, picking up these changes. The default value ("false") means that such changes will be ignored. NOTE: While this feature is very useful during development, it requires overhead to do the checking. This capability should generally not be used in deployed production applications.
- trusted. Set to "true" if this application requires access to Tomcat 3.3 internal classes. Normally, this will only be required for the administration application that ships with Tomcat.