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

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

问题描述

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

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

推荐答案

使用构建工具,例如< a href =http://ant.apache.org/> Ant 或 Maven的。两者都可以以比使用例如使用例如更好的方式更好的方式管理依赖关系。 查找 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任务。 NetBeans Eclipse IDEA 以及更多内容也支持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天全站免登陆