Java Makefile基础 [英] Basics on java makefile

查看:92
本文介绍了Java Makefile基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java和makefile的新手,我想要一些关于makefile的介绍性信息.通常在网上找到的信息大部分是示例,并且是高水平的.这是我对Makefile的一些特定/天真的问题:

I am new to java and makefile, and I'd like some introductory information about a makefile. The information that's typically found online are mostly examples and high level. Here's some specific/naive questions I have about makefile:

  1. makefile的目标是什么类型的文件? .class和.java?

  1. What type of files are targets of a makefile? .class and .java?

makefile对那些项目文件有什么作用?我在Eclipse中完成了项目,因此.class文件存储在bin中,.java文件存储在scr中. makefile在这些文件之间建立什么样的连接?

What does a makefile do to those project files? I did my projects in Eclipse, so the .class files are stored in bin, and .java files are stored in scr. What kind of connection does makefile make between these files?

makefile的结果是什么? makefile的目的是告诉编译器如何制作可执行文件,因此结果是当前目录中有一个新的可执行文件,是吗?

What is the result of a makefile? makefile's purpose is tell compiler how to make an executable, so the result is a new executable file in the current directory, yes?

我应该在哪里放置makefile?在bin文件夹中? scr文件夹?将所有苍蝇混合在一个目录下,并放在该目录下?

Where should I place the makefile? In the bin folder? scr folder? mingle all flies under one directory and put it under there?

最后,我为我的项目制作了一个小的makefile,该文件应编译3个类.它不起作用,我也不知道为什么:

lastly, I made a small makefile for my project which should compile 3 classes. It's not working and I don't know why:

makefile:

JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
    $(JC) $(JFLAGS) $*.java

CLASSES = \
    DNA.java \
    C.java \
    fastmatch.java 

default: classes

classes: $(CLASSES:.java=.class)

clean:
    $(RM) *.class

我做错了吗?我只是将所有内容放在一个文件夹下,然后在命令行中键入"make".我想我在这里错过了一些大图景,所以如果有人可以向我解释一下,我将非常感谢.谢谢

Did I do something wrong? I just put everything under one folder and typed "make" in command line. I think i'm missing some big picture here so I'd really appreciate if someone can explain them to me. Thanks

推荐答案

make不是用于构建Java的正确工具.您应该使用 Ant Maven 或其他Java-建筑工具.用make完成工作是可能的,但是对于除最琐碎的Java程序以外的任何东西,您最终都会得到一个makefile,该文件会删除所有内容并每次都从头开始重新编译.

make is not the correct tool for building Java. You should use Ant or Maven or another Java-building tool. It is possible to get the job done with make, but for anything but the most trivial Java programs, you will end up with a makefile that deletes everything and recompiles from scratch every time.

在C和朋友的土地上做得很好.在那里,源文件依赖于它导入的所有标头,而标头不依赖任何内容(因为它们没有被编译),因此依赖树不会太深.在Java中,每个类都依赖于它导入的每个类,而后者又依赖于其他类,因此通常情况下,如果不编译项目中的所有其他类,则无法编译单个类.您可以 在您的makefile中进行描述,但是要在不到一秒钟的时间内完成Ant的工作将需要数小时的繁琐工作.

Make works well in the land of C and friends. There, a source file depends on all the headers that it imports, and the headers depend on nothing (because they don't get compiled), so your dependency tree is not excessively deep. In Java, every class depends on every class it imports, which depend on further classes, so it's frequently the case that a single class can't be compiled without compiling every other class in the project. You could describe that in your makefile, but it would be hours of tedious work to do what Ant does in less than a second.

所有所说的话:

  1. 目标"是makefile生成的东西.如果您不是在编写可编写代码的代码,则.java文件不是目标
  2. 在您发布的makefile中,.class文件将最终与相应的.java文件位于同一位置
  3. makefile的结果基本上可以是任何东西. make本身就是一种相当强大的语言. this 生成文件的结果是三个已编译的Java类(可能更多,因为javac可能会找到更多要编译的类,或者您的某些类可能具有内部类.同样,这就是make是Java的坏工具)
  4. makefile通常位于根项目目录中.通常,复杂的项目还会有其他用于子目录的makefile
  1. "targets" are things that the makefile is generating. If you're not writing code that writes code, then the .java files are not the targets
  2. in the makefile you've posted, .class files will end up in the same location as corresponding .java files
  3. the result of a makefile can basically be anything at all. make is a fairly powerful language in its own right. The result of this makefile is three compiled Java classes (possibly more, because javac might find more classes to compile or some of your classes might have inner classes. Again, this is why make is a bad tool for Java)
  4. a makefile typically lives in the root project directory. Often, complex projects will have other makefiles for sub-directories

这篇关于Java Makefile基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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