且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用现有的ant build.xml文件创建一个eclipse项目

更新时间:2023-11-20 09:11:10

我不建议在这个阶段使用Ant路线,因为它会使事情复杂化。 Maven将是最终的方式,或者Gradle - 但是这一点远远超出了范围。 Eclipse不需要ant或build.xml ant相关文件!

I wouldnt recommend going the Ant route at this stage as it complicates things. Maven would be the way to go in the end, or Gradle - but that's way out of the scope at this point. Eclipse doesn't need ant or a build.xml ant related file!

在Eclipse中执行以下操作

In Eclipse do the following


  1. 如果你使用普通的旧Java,创建一个新的Java项目,如果你打算使用J2EE,那么创建一个新的Java EE,EAR项目,然后你可以在其中创建和添加一个新的EJB或者WAR((WEB)动态Web项目)。 但是 EJB或WAR项目不必驻留在EAR中,而EAR目前仅适用于JBoss,WebSphere或GlassFish等J2EE应用程序服务器

  2. 创建项目后,将您的java源代码复制到eclipse创建的src目录中 - 您可以右键单击eclipse中的src文件夹,选择属性,然后选择资源,它将告诉您它的路径。 / li>
  3. 如果您的项目需要支持库/包(jar),那么最简单的事情就是创建一个lib文件夹并将其放在EAR项目的父目录中,如果您正在使用J2EE,那么EJB项目父目录或WAR项目父目录,如果您只是执行普通的旧Java,则在与src目录相同的目录级别创建lib文件夹。把你的罐放在那里。

  4. Eclipse不会立即找到那些罐子:

  5. 在eclipse选择属性中右键单击项目

  6. 在左窗格中选择java构建路径

  7. 单击库选项卡

  8. 单击添加外部罐子按钮

  9. 导航/浏览到lib文件夹并选择所有jar

  10. 单击Apply / Okay

  11. Eclipse应自动构建(任何更改),但如果没有,请单击项目菜单并自动单击构建。有时您可能还需要清理,然后重建

  1. Create a new Java Project if you're using plain old Java, if you plan on using J2EE, then create a new Java EE, EAR project in which you would then create and add optionally a new EJB or WAR ((WEB)Dynamic Web Project). But an EJB or WAR project does not have to reside within a EAR and an EAR only will work at the moment with a J2EE Application server like JBoss, WebSphere or GlassFish
  2. Once the projects created, copy your java source code to the "src" directory that was created by eclipse - you can right click the src folder in eclipse, select properties, then resources and it will tell you the path to it.
  3. If your project requires supporting libraries/packages (jars) then the easiest thing to do though not totally recommended is to create a "lib" folder and place it in either the EAR projects parent directory, the EJB projects parent directory, or the WAR projects parent directory if you're doing J2EE, if you're just doing plain old java, then create the lib folder at the same directory level as the "src" directory. Put your jars in there.
  4. Eclipse wont immediately find those jars so:
  5. Right click the project in eclipse select properties
  6. Select java build path in left pane
  7. Click the libraries tab
  8. Click the add external jars button
  9. Navigate/browse to the "lib" folder and select all the jars
  10. Click Apply/Okay
  11. Eclipse should build automatically (on any change), but if not click the Project menu and click build automatically. Sometimes you might also have to clean, which then rebuilds

这应该是启动最小Java或J2EE eclipse项目的基本步骤。让我知道对这个答案的评论,我可以修改它,如果需要更正确地反映你在做什么

This should be the basic steps on getting a minimal Java or J2EE eclipse project started. Let me know in comments to this answer and I can modify it if need be to more correctly reflect what you're doing