Java 编译器正在使用旧版本的源代码 [英] Java compiler is using old version of source code

查看:38
本文介绍了Java 编译器正在使用旧版本的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常烦人的问题,想象一下我编译了文件 FooBar.java:

I am experiencing a very annoying problem to me, imagine I compile the file FooBar.java:

$ javac FooBar.java

$ javac FooBar.java

它编译成功,然后我像往常一样运行它:

It compiles sucefully and then I run it as usual:

$ java FooBar <.txt

$ java FooBar < in.txt

我得到了预期的输出,问题是,如果我更改源代码 (FooBar.java) 以打印其他内容并再次编译,我会得到与第一次相同的输出!

I get the output as expected, the deal is, if I change the source code (FooBar.java) to print something else and compile it again I get the same output as the first time!

这真的让我很生气... javac 有缓存吗?即使我删除 FooBar.class 并重新编译,我也会从早期源代码中获得输出.我发现解决这个问题的唯一方法是删除 FooBar.java 并创建一个具有不同名称的新文件(我只是复制粘贴了代码),这是有效的.

This is really making me mad... is there any cache for the javac? Even if I delete FooBar.class and recompile I get the output from the early source code. The only way I found to solve this is to delete FooBar.java and create a new file with a diferent name (I just copy-pasted the code), this works.

这个错误(?)真的困扰着我.我已经寻找解决方案或解释为什么会发生这种情况,但没有运气.

This bug (?) is really bugging me. I've searched for a solution or an explanation to why this happens but with no luck.

这似乎与我的问题有关,但并不完全,因为我没有使用任何 IDE 并且 Classpath 指向我的工作文件夹:http://www.coderanch.com/t/519372/java/java/Executing-Old-Code

This seems to be related to my problem but not completely as I am not using any IDE and the Classpath points to my working folder: http://www.coderanch.com/t/519372/java/java/Executing-Old-Code

我想知道是什么导致了这个,因为我不想每次更新源代码时都创建一个新文件......我在 Windows 上使用 Java 1.6.0_27

I would like to find out what's causing this as I don't want to make a new file everytime I update source code... I'm on Windows with Java 1.6.0_27

感谢阅读...

推荐答案

问题不会是缓存.试试这个:

The problem won't be caching. Try this:

  1. 查看 FooBar.class 文件上的时间戳(这就是 RUN)
  2. 再次编译 javac...
  3. 再次查看时间戳.有没有改变?如果没有,您正在编译到某个地方.
  4. 其他海报对包裹的评论可以解释这一点.也可以通过设置/更改您的类路径来解释

这篇关于Java 编译器正在使用旧版本的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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