【技術貼】解決使用maven jetty啟動后無法加載修改過后的靜態資源


 

如何使用jetty自動熱部署修改后的所有文件,比如js,jpg,class等,哇咔咔 太爽啦比tomcat舒服多了。

 

jetty模式是不能修改js文件的,比如你現在調試前端js,發現在myeclipse/eclipse的源碼里面無法修改文件,點都不讓你點,所以,你只能采用一些辦法,更改jetty的模式配置。

Look:

1.從jetty.jar中解出webdefault.xml(位於org.mortbay.jetty.webapp包下)這個文件,在<servlet>節點下把這個useFileMappedBuffer參數設為false,大概就在153行左右,外國人寫的N多注釋結束的20行之后。

<init-param>
    <param-name>useFileMappedBuffer</param-name>
    <!-- change to false -->
    <param-value>true</param-value>
 </init-param>

2.把修改后的webdefault.xml文件放到一個地方,隨便放,我放在了src/main/resources下了

3.修改你的maven核心pom.xml文件

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.3.0.v20110203</version>
    <configuration>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
        <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
        <webAppConfig>
            <contextPath>/report</contextPath>
        </webAppConfig>
    </configuration>
</plugin>

webDefaultXml : 我們在第一步修改好的xml文件

webAppSourceDirectory :你的js,css的父級目錄,目的是動態部署到jetty你的靜態文件。

webAppConfig : 工程根目錄,目的是為了編譯java源碼后自動部署到jetty,爽吧,不用部署了,自動熱部署哦~~ ctrl + s 之后你就可以在瀏覽器觀看效果咯~~

4.直接項目右鍵 運行maven的命令 jetty:run

控制台 :

[INFO] Started Jetty Server

[INFO] Starting scanner at interval of 10 seconds.

就可以了,隨便修改吧,你的項目文件就聽你的話了。。太爽了。

 

5.附錄我所有的pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.riambsoft</groupId>
    <artifactId>report</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>report</name>
    <url>http://www.riambsoft.com</url>
    <dependencies>
 
     
 
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.8.1</version>
        </dependency>
        <!-- jasperreports end -->
 
       
 
        <dependency>
            <groupId>com.oracle.driver</groupId>
            <artifactId>jdbc-driver</artifactId>
            <version>10g</version>
        </dependency>
 
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-archiver</artifactId>
            <version>1.0-alpha-7</version>
        </dependency>
 
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.1</version>
        </dependency>
 
      
 
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>1.4.7</version>
        </dependency>
 
 
        <dependency>
            <groupId>com.riambsoft</groupId>
            <artifactId>rsclient.web</artifactId>
            <version>1.0.0_without_RS10</version>
        </dependency>
 
    </dependencies>
    <build>
        <finalName>report</finalName>
        <plugins>
         
              
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>7.3.0.v20110203</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
                    <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
                    <webAppConfig>
                        <contextPath>/report</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
              
             
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.25</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
                    <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
                </configuration>
            </plugin>
             
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
             
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <server>tomcat</server>
                    <url>http://localhost:8080/manager/html</url>
                    <path>/report</path>
                </configuration>
            </plugin>
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
 

 
            <!-- 測試覆蓋率分析插件 -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
 
        </plugins>
    </build>
    <description></description>
</project>

2013年7月25日10:15:05

落雨

qq 394263788

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM