琴瑟和鸣--让同一项目在NetBeans和Eclipse平台下和谐相处,协同开发

11 篇文章 0 订阅
11 篇文章 0 订阅
在Java IDE世界里,Eclipse和NetBeans是平台主导者。无论是CodeGear的JBuilder 2007,BEA 的Workshop Studio,还是IBM 的Websphere Studio,因为都是建立的在Eclipse平台基础上的,所以缺省的构建(Build)方式都是Eclipse Native的。同时,Eclipse支持External Tools方式,其中有Ant Build方式。这样为采用其它IDE建立的项目搭建了一个沟通的桥梁。
在一个开发小组中,本应该要统一开发环境。但是有时候,采用NetBeans 平台加上EnterPack和Visual Web Pack之后,可以简化SOA的Web Services和BPEL以及JSF 2.0的开发。NetBeans本身完全采用ant 方式管理工程。这样我们可以建立一个在NetBeans和Eclipse共享的项目。
步骤如下:
1.在NetBeans下建立项目
首先在NetBeans下建立一个叫HelloWorld的示例项目。在NetBeans的项目视图和文件视图如图1和图所示。
在NetBeans的项目中一般至少包含了Source Packages,Test Packages,Libraries和Test Libraries四个目录。其结构图如如图1。

 

图1 NetBeans项目结构图

在NetBeans的文件结构至少包含nbproject, src和test三个子目录。文件结构图如图2所示。
在项目的文件夹下面有ant的标准构建文件build.xml,其内容如表所示。
<? 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"/

主要的内容实际上在nbproject/build-impl.xml里。

 

图2 NetBeans文件结构图

那么构建过后的class文件和jar到底放置在什么地方。

切换到project视图,点击右键,在弹出菜单选择“Build Project”(如图3所示),对项目进行构建。

 

图3

再切换到File视图,将会发现多出了build和dist及其子文件夹。如图4所示。

 

图4

原来,NetBeans构建过后,将产生的类放置到了build文件夹的classes下面,将生成的jar包放置到了dist下面。
通过搜索,build.classes.dir属性和dist.dir是在project.properties文件里定义的。为了将项目引入到eclipse作准备,修改为:
build.classes.dir=${build.dir}/

dist.dir=bin

自此,在HelloWorld项目在NetBeans下已经完工。

2.将HelloWorld Project 引入到Eclipse
打开Eclipse,从菜单"File->New"选择,将弹出项目向导。在向导中选择"Java 项目"。如图5所示。

 

 

图5

点击下一步,在新的向导页中,选择"从现有资源创建项目"选项,然后再点击“下一步”。如图6所示。

 

图6

这时,调整缺省输出目录,然后点击“完成”按钮。

 

图7

至此,NetBeans下的项目完整地引入到了Eclipse平台里。像其它的Eclipse项目一样进行操作了。
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个问题没有一个明确的答案,因为每个人的需求和偏好都不同。NetBeansEclipse都是流行的Java集成开发环境(IDE),它们都有自己的优点和缺点。 NetBeans是一个开源的IDE,它的界面简单易用,适合初学者。它内置了很多功能,如代码自动完成、调试器、版本控制等等。同时,NetBeans也支持多种编程语言,如Java、C++、PHP等等。 Eclipse也是一个开源的IDE,它的界面更加灵活,可以根据用户的需求进行自定义。Eclipse也有很多插件可供选择,可以扩展其功能。Eclipse也支持多种编程语言,如Java、C++、Python等等。 总的来说,NetBeans适合初学者和小型项目,而Eclipse适合有经验的开发者和大型项目。但是,最终选择哪个IDE还是要根据个人需求和偏好来决定。 ### 回答2: NetBeansEclipse都是Java开发中很流行的集成开发环境,它们都具备丰富的功能并且都是开源软件,因此对于哪一个更好这个问题有很多争议,而选择其中一个取决于个人需求和习惯。 首先,NetBeans的主要优点是易用性和直观性,它具有良好的集成开发环境,可以快速地实现和开发Java应用程序,也可以使用其他语言和开发平台进行开发。它的编码自动完成和错误高亮功能都做得不错,也有一些强大的拖拽式界面编辑器。它还有非常强大的调试功能和其他可定制的插件。 而Eclipse则更加注重扩展性和自定义性,它有庞大的开发社区和插件库,内置有很多强大的功能和插件,可以让开发者在写代码、调试和测试过程中得到更好的支持和帮助。但是它的学习曲线比较陡峭,需要一定的学习成本和时间。 综上所述,两个开发工具各有千秋,选择哪一个更好取决于个人需求和偏好。如果您更注重易用性和快速开发,那么NetBeans可能是更好的选择;如果您需要更多的扩展性和自定义性,那么Eclipse会更适合您。最好的办法是使用这两个开发工具进行比较和试用,找到最适合自己的。 ### 回答3: NetBeansEclipse都是当前比较流行的开源集成开发环境(IDE),它们在很多方面类似,但也有一些不同。以下是我的意见: 1. 用户界面:Eclipse的用户界面比NetBeans更加简约,适合那些更愿意 DIY 和专注于代码编辑的程序员。NetBeans则更注重用户体验,界面更加友好,适合初学者和非技术人员使用。 2. 扩展性:Eclipse插件的数量加速增加,因此对于需要大量定制化和插件的高级开发者来说,Eclipse是绝佳选择。NetBeans虽然有一些插件,但是Eclipse更加丰富和灵活。 3. 管理工具:NetBeans捆绑了一个强大的项目管理工具,因此对于那些需要集成开发环境和工具来管理项目开发人员来说,NetBeans可能是首选。Eclipse则不像NetBeans那样有强劲的项目管理能力,因此对于一些小型和简单的项目Eclipse可能是更好的选择。 4. 编辑器:NetBeans拥有更加用户友好的编辑器,你可以直接在编辑器中运行代码和测试代码等。Eclipse也有强大的编辑器,但是对于初学者来说,NetBeans会更加友好,易于上手。 基于上述理由,我个人认为,NetBeansEclipse都有他们优点和劣势。不同的项目和需求需要选择适合的IDE。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值