Chapter 1 - Netbeans配置和运行Jetty源代码

编程技术  /  houtizong 发布于 3年前   92
在Netbeans里面新建一个Java project, 然后把Jetty 6的源码加进来,添加一些必要的依赖包,添加ant脚本,开启调试。

1. 新建一个Java project, 加入Jetty 6 source package

   你可以从这个url拿到源码包:
   http://dist.codehaus.org/jetty/jetty-6.1.26/jetty-6.1.26-src.zip

2. 添加编译jetty时必须的依赖包:

   servlet-api-2.5-20081211.jar
   slf4j-api-1.3.1.jar


3. 添加配置文件:

   etc/jetty.xml
   etc/webdefault.xml
   realm.properties

4. 配置Netbeans脚本:
  
<project xmlns="http://www.netbeans.org/ns/project/1">    <type>org.netbeans.modules.ant.freeform</type>    <configuration>        <!-- Either of the below two is applicable -->        <!--<general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">-->        <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2">            <name>jetty</name>            <properties>                <property name="ant.script">nbproject/targets.xml</property>                <property name="jetty.script">build/jetty-build.xml</property>            </properties>            <folders>                <source-folder>                    <label>jetty</label>                    <location>.</location>                    <encoding>windows-1252</encoding>                </source-folder>                <source-folder>                    <label>Java Sources</label>                    <type>java</type>                    <location>src</location>                    <encoding>windows-1252</encoding>                </source-folder>            </folders>            <ide-actions>                <action name="build">                    <script>${jetty.script}</script>                    <target>nbbuild</target>                </action>                <action name="clean">                    <script>${jetty.script}</script>                    <target>clean</target>                </action>                <action name="run">                    <script>${jetty.script}</script>                    <target>nbrun</target>                </action>                <action name="debug">                    <script>${jetty.script}</script>                    <target>nbdebug</target>                </action>            </ide-actions>            <view>                <items>                    <source-folder style="tree">                        <label>Web folder</label>                        <location>webapps</location>                    </source-folder>                    <source-folder style="tree">                        <label>Jetty configs</label>                        <location>webapps/WEB-INF/etc</location>                    </source-folder>                    <source-folder style="packages">                        <label>Java src</label>                        <location>src</location>                    </source-folder>                </items>                <context-menu>                    <ide-action name="build"/>                    <ide-action name="clean"/>                    <ide-action name="javadoc"/>                    <ide-action name="run"/>                    <ide-action name="test"/>                    <ide-action name="debug"/>                </context-menu>            </view>        </general-data>        <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/3">            <compilation-unit>                <package-root>src</package-root>                <classpath mode="compile"></classpath>                <built-to>classes</built-to>                <javadoc-built-to>doc</javadoc-built-to>                <source-level>1.6</source-level>            </compilation-unit>        </java-data>    </configuration></project>


5. 添加jetty脚本

   每次compile时候,会根据更改情况,生成新的classes。这些classes会被jar(update)到jetty-6.1.26.jar。启动IDE的debugger,然后启动jetty6,并把jetty6附加到debugger上,这样可以调试代码的运行

   a. build脚本
   javac.source=1.6
   javac.target=1.6
   JAVAC_EXE=
   srcDir=source directory
   outDir=output directory
  
    <target name="nbbuild" depends="configProperties">        <javac source="${javac.source}" target="${javac.target}"            executable="${JAVAC_EXE}" fork="yes" destdir="${outDir}"            classpath="${outDir}" classpathref="libraries"            optimize="off" verbose="off" debug="on"            memoryInitialSize="512M" memoryMaximumSize="768M">            <src path="${srcDir}"/>            <include name="**/*.java"/>        </javac>                <jar update="true" compress="true" jarfile="${jettyOutDir}\\lib\\jetty-6.1.26.jar">            <manifest>                <attribute name="Build-Date" value="${build.time}"/>                <attribute name="Build-User" value="${user.name}"/>                <attribute name="Build-File" value="${ant.file}"/>                <attribute name="Build-Location" value="${prefix}"/>                <attribute name="Build-Platform" value="${os.name} ${os.version}(${os.arch})"/>                <attribute name="Specification-Title" value="${java.specification.name}"/>                <attribute name="Specification-Vendor" value="${java.vendor}"/>                <attribute name="Specification-Version" value="${java.version}"/>                <attribute name="CopyrightNotice" value="Copyright (c) 2012-${build.year} ${corp.name}"/>                <attribute name="Implementation-Title" value="${ant.project.name} - HTTPS Handler"/>                <attribute name="Implementation-Vendor" value="${corp.name}"/>                <attribute name="Implementation-Version" value="${build.version}"/>            </manifest>            <fileset dir="${outDir}">                <include name="org/mortbay/**/*.class"/>            </fileset>        </jar>    </target>   


   b. debug脚本
  
    <target name="nbdebug" depends="nbbuild">        <!-- Copy the necessary configuration files and libraries to the jetty output direction -->        <copy todir="${jettyOutDir}" file="jetty/start.jar" overwrite="no"/>        <copy todir="${jettyOutDir}/etc" overwrite="no">            <fileset dir="jetty/etc">                <include name="jetty.xml"/>                <include name="webdefault.xml"/>                <include name="configure.dtd"/>                <include name="realm.properties"/>            </fileset>        </copy>        <copy todir="${jettyOutDir}/lib" overwrite="no">            <fileset dir="lib">                <include name="**/*.jar"/>            </fileset>        </copy>        <copy todir="${jettyOutDir}/ext" overwrite="no">            <fileset dir="jetty/ext">                <include name="*.jar"/>            </fileset>        </copy>        <mkdir dir="${jettyOutDir}/lib"/>        <mkdir dir="${jettyOutDir}/bin/logs"/>        <copy todir="${jettyOutDir}/webapps" overwrite="no">            <fileset dir="webapps">                <include name="**/*"/>            </fileset>        </copy>        <!-- Start the debugger -->        <nbjpdastart name="Jetty 6" addressproperty="jpda.address2" transport="dt_socket">            <sourcepath>                <pathelement path="${srcDir}"/>            </sourcepath>        </nbjpdastart>                <!-- Start the application -->        <java jar="${jettyOutDir}\\start.jar" fork="yes" dir="${jettyOutDir}\\bin" failonerror="true"            classpathref="libraries" jvm="${java.executable}">            <jvmarg value="-Xdebug"/>            <jvmarg value="-mx256M"/>            <jvmarg value="-Xnoagent"/>            <jvmarg value="-Djetty.home=."/>            <jvmarg value="-Djava.compiler=none"/>            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address2}"/>            <jvmarg value="-DSTOP.PORT=-1"/>            <jvmarg value="-Xverify:none"/>            <jvmarg value="-Xbootclasspath/a:${jettyOutDir}\\ext\\mail.jar"/>            <jvmarg value="-Dprimary.address=10.158.171.103"/>            <jvmarg value="-Dprimary.port=8080"/>        </java>    </target>   


6. 调试源代码

点击debug,可以看到output panel上有输出,debug toolbar也会出现。在jetty代码里加个断点,就可以调试了。

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客