编译所有子文件夹中的java文件? [英] Compiling java files in all subfolders?

查看:30
本文介绍了编译所有子文件夹中的java文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Unix 上使用 javac 编译所有子文件夹中的所有 java 文件?

How to compile all java files in all subfolders on Unix, using javac?

推荐答案

使用构建工具,例如 AntMaven.两者都可以让您以比使用例如完成的方式更好的方式管理依赖项find UNIX 工具.And 和 Maven 还允许您定义除编译之外要执行的自定义任务.此外,Maven 还带有用于管理远程存储库中的外部依赖项的约定,以及用于运行单元测试和支持持续集成的功能的约定.

Use a build tool such as Ant or Maven. Both lets you manage dependencies in a much better way than can be accomplished using e.g. the find UNIX tool. Both And and Maven also lets you define custom tasks to be performed in addition to compilation. Maven furthermore comes with conventions for managing external dependencies in remote repositories, as well as conventions for running unit tests and features that support continuous integration.

即使您只需要偶尔编译一次源文件,您也可能会发现设置一个简单的 Ant build.xml 文件最终可以节省大量时间.

Even if you just need to compile your source files once in a while, you'll probably find that setting up a simple Ant build.xml file can be a big time saver in the end.

最后,大多数流行的 IDE 和代码编辑器应用程序都与 Ant 构建脚本进行了某种集成,因此您可以从编辑器中运行所有 Ant 任务.NetBeansEclipseIDEA 等也内置了对 Maven 的支持.

Finally, most of the popular IDE and code editor applications has some kind of integration with Ant build scripts, so you can run all the Ant tasks from within the editor. NetBeans, Eclipse, IDEA and more also has built-in support for Maven.

如果您是 Ant 的新手,请先阅读这个.以下是链接中的示例构建文件:

Read this first, if you're new to Ant. Below is the example build file from the link:

<project name="MyProject" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

熟悉 Ant 后,您会发现迁移到 Maven 会更容易.

Once you're familiar with Ant, you'll find it easier to move to Maven.

这篇关于编译所有子文件夹中的java文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆