设为首页 收藏本站
查看: 496|回复: 0

[经验分享] Chapter 1

[复制链接]

尚未签到

发表于 2017-2-26 13:03:39 | 显示全部楼层 |阅读模式
在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代码里加个断点,就可以调试了。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-347485-1-1.html 上篇帖子: Maven Jetty Plugin 配置指南(二) 下篇帖子: Jetty实战之 嵌入式运行Jetty实现简单文件服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表