網(wǎng)路冷眼@BlogJava

          熙熙攘攘一閑人 以冷靜的眼光觀察技術(shù)
          posts - 88, comments - 193, trackbacks - 0, articles - 28
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          在Java IDE世界里,Eclipse和NetBeans是平臺主導(dǎo)者。無論是CodeGear的JBuilder 2007,BEA 的Workshop Studio,還是IBM 的Websphere Studio,因為都是建立的在Eclipse平臺基礎(chǔ)上的,所以缺省的構(gòu)建(Build)方式都是Eclipse Native的。同時,Eclipse支持External Tools方式,其中有Ant Build方式。這樣為采用其它IDE建立的項目搭建了一個溝通的橋梁。

          在一個開發(fā)小組中,本應(yīng)該要統(tǒng)一開發(fā)環(huán)境。但是有時候,采用NetBeans 平臺加上EnterPack和Visual Web Pack之后,可以簡化SOA的Web Services和BPEL以及JSF 2.0的開發(fā)。NetBeans本身完全采用ant 方式管理工程。這樣我們可以建立一個在NetBeans和Eclipse共享的項目。

          步驟如下:

          1.在NetBeans下建立項目

          首先在NetBeans下建立一個叫HelloWorld的示例項目。在NetBeans的項目視圖和文件視圖如圖1和圖所示。

          在NetBeans的項目中一般至少包含了Source Packages,Test Packages,Libraries和Test Libraries四個目錄。其結(jié)構(gòu)圖如如圖1。

          圖1 NetBeans項目結(jié)構(gòu)圖

          在NetBeans的文件結(jié)構(gòu)至少包含nbproject, src和test三個子目錄。文件結(jié)構(gòu)圖如圖2所示。
          在項目的文件夾下面有ant的標(biāo)準(zhǔn)構(gòu)建文件build.xml,其內(nèi)容如表所示。
          <? xml?version="1.0"?encoding="UTF-8" ?>
          <!-- ?You?may?freely?edit?this?file.?See?commented?blocks?below?for? -->
          <!-- ?some?examples?of?how?to?customize?the?build.? -->
          <!-- ?(If?you?delete?it?and?reopen?the?project?it?will?be?recreated.)? -->
          < project? name ="HelloWorld" ?default ="default" ?basedir ="." >
          ????
          < description > Builds,?tests,?and?runs?the?project?HelloWorld. </ description >
          ????
          < import? file ="nbproject/build-impl.xml" />
          ????
          <!--

          ????There?exist?several?targets?which?are?by?default?empty?and?which?can?be?
          ????used?for?execution?of?your?tasks.?These?targets?are?usually?executed?
          ????before?and?after?some?main?targets.?They?are:?

          ??????-pre-init:?????????????????called?before?initialization?of?project?properties
          ??????-post-init:????????????????called?after?initialization?of?project?properties
          ??????-pre-compile:??????????????called?before?javac?compilation
          ??????-post-compile:?????????????called?after?javac?compilation
          ??????-pre-compile-single:???????called?before?javac?compilation?of?single?file
          ??????-post-compile-single:??????called?after?javac?compilation?of?single?file
          ??????-pre-compile-test:?????????called?before?javac?compilation?of?JUnit?tests
          ??????-post-compile-test:????????called?after?javac?compilation?of?JUnit?tests
          ??????-pre-compile-test-single:??called?before?javac?compilation?of?single?JUnit?test
          ??????-post-compile-test-single:?called?after?javac?compilation?of?single?JUunit?test
          ??????-pre-jar:??????????????????called?before?JAR?building
          ??????-post-jar:?????????????????called?after?JAR?building
          ??????-post-clean:???????????????called?after?cleaning?build?products

          ????(Targets?beginning?with?'-'?are?not?intended?to?be?called?on?their?own.)

          ????Example?of?inserting?an?obfuscator?after?compilation?could?look?like?this:

          ????????<target?name="-post-compile">
          ????????????<obfuscate>
          ????????????????<fileset?dir="${build.classes.dir}"/>
          ????????????</obfuscate>
          ????????</target>

          ????For?list?of?available?properties?check?the?imported?
          ????nbproject/build-impl.xml?file.?


          ????Another?way?to?customize?the?build?is?by?overriding?existing?main?targets.
          ????The?targets?of?interest?are:?

          ??????-init-macrodef-javac:?????defines?macro?for?javac?compilation
          ??????-init-macrodef-junit:?????defines?macro?for?junit?execution
          ??????-init-macrodef-debug:?????defines?macro?for?class?debugging
          ??????-init-macrodef-java:??????defines?macro?for?class?execution
          ??????-do-jar-with-manifest:????JAR?building?(if?you?are?using?a?manifest)
          ??????-do-jar-without-manifest:?JAR?building?(if?you?are?not?using?a?manifest)
          ??????run:??????????????????????execution?of?project?
          ??????-javadoc-build:???????????Javadoc?generation
          ??????test-report:??????????????JUnit?report?generation

          ????An?example?of?overriding?the?target?for?project?execution?could?look?like?this:

          ????????<target?name="run"?depends="HelloWorld-impl.jar">
          ????????????<exec?dir="bin"?executable="launcher.exe">
          ????????????????<arg?file="${dist.jar}"/>
          ????????????</exec>
          ????????</target>

          ????Notice?that?the?overridden?target?depends?on?the?jar?target?and?not?only?on?
          ????the?compile?target?as?the?regular?run?target?does.?Again,?for?a?list?of?available?
          ????properties?which?you?can?use,?check?the?target?you?are?overriding?in?the
          ????nbproject/build-impl.xml?file.?

          ????
          -->
          </ project >

          ?

          在列表中可以看出,有這樣的描述
          import?file="nbproject/build-impl.xml"/

          主要的內(nèi)容實際上在nbproject/build-impl.xml里。

          圖2 NetBeans文件結(jié)構(gòu)圖

          那么構(gòu)建過后的class文件和jar到底放置在什么地方。

          切換到project視圖,點擊右鍵,在彈出菜單選擇“Build Project”(如圖3所示),對項目進行構(gòu)建。

          圖3

          再切換到File視圖,將會發(fā)現(xiàn)多出了build和dist及其子文件夾。如圖4所示。

          圖4

          原來,NetBeans構(gòu)建過后,將產(chǎn)生的類放置到了build文件夾的classes下面,將生成的jar包放置到了dist下面。
          通過搜索,build.classes.dir屬性和dist.dir是在project.properties文件里定義的。為了將項目引入到eclipse作準(zhǔn)備,修改為:
          build.classes.dir=${build.dir}/

          dist.dir=bin

          自此,在HelloWorld項目在NetBeans下已經(jīng)完工。

          2.將HelloWorld Project 引入到Eclipse

          打開Eclipse,從菜單"File->New"選擇,將彈出項目向?qū)АT谙驅(qū)е羞x擇"Java 項目"。如圖5所示。

          ?

          圖5

          點擊下一步,在新的向?qū)ы撝校x擇"從現(xiàn)有資源創(chuàng)建項目"選項,然后再點擊“下一步”。如圖6所示。

          圖6

          這時,調(diào)整缺省輸出目錄,然后點擊“完成”按鈕。

          圖7

          至此,NetBeans下的項目完整地引入到了Eclipse平臺里。像其它的Eclipse項目一樣進行操作了。

          評論

          # re: 琴瑟和鳴--讓同一項目在NetBeans和Eclipse平臺下和諧相處,協(xié)同開發(fā)  回復(fù)  更多評論   

          2007-01-01 15:16 by Anubis
          從Eclipse建立的項目能否搞到NB下面呢?

          # re: 琴瑟和鳴--讓同一項目在NetBeans和Eclipse平臺下和諧相處,協(xié)同開發(fā)  回復(fù)  更多評論   

          2007-01-01 21:17 by 網(wǎng)路冷眼@BlogJava
          @Anubis
          NetNeans可以引入Eclipse或者JBuilder 2005和JBuilder 2006的項目。前提條件是必需從NetBeans升級中心(NetBeans UpdateCenter)下載必要的module:JBuilder Project Importer 或者 Eclipse Project Importer.
          對于Eclipse項目,既可從workspace里引入相互關(guān)聯(lián)的項目集,也可忽略依賴關(guān)系引入單個項目。對于JBuilder項目,可以引入標(biāo)準(zhǔn)的具有依賴關(guān)系的Java SE項目。

          # re: 琴瑟和鳴--讓同一項目在NetBeans和Eclipse平臺下和諧相處,協(xié)同開發(fā)  回復(fù)  更多評論   

          2007-01-03 17:29 by Anubis
          Thanks.

          # re: 琴瑟和鳴--讓同一項目在NetBeans和Eclipse平臺下和諧相處,協(xié)同開發(fā)  回復(fù)  更多評論   

          2007-01-03 19:31 by 網(wǎng)路冷眼@BlogJava
          @Anubis
          U r welcome!
          主站蜘蛛池模板: 新和县| 武穴市| 苗栗县| 呼和浩特市| 陇南市| 盘锦市| 沙洋县| 安康市| 呼伦贝尔市| 黔西县| 贵州省| 冀州市| 滨州市| 来凤县| 高青县| 汝南县| 宁海县| 吉水县| 尉氏县| 通化县| 介休市| 云林县| 吉隆县| 新宁县| 长子县| 车险| 卢龙县| 筠连县| 合肥市| 若尔盖县| 全南县| 尼木县| 缙云县| 安阳县| 富源县| 西宁市| 通渭县| 东乡| 石河子市| 新干县| 望江县|