简体   繁体   English

Eclipse运行旧版本的Java程序

[英]Eclipse running old version of Java program

I have Eclipse 4.5.2. 我有Eclipse 4.5.2。

Suppose I write a program VERSION1. 假设我编写了一个程序VERSION1。

Then, I change some things (the amount of changes seems to be of no importance) and get VERSION2. 然后,我更改一些内容(更改的数量似乎无关紧要),并获得VERSION2。

If I now run the program using the "Run" button, it (almost?) always starts VERSION1. 如果现在我使用“运行”按钮运行程序,则它(几乎?)总是启动VERSION1。 When I click the "Run" button again without changing anything, it runs VERSION2. 当我再次单击“运行”按钮而不进行任何更改时,它将运行VERSION2。 I don't see any new compilation going on between the runs and I cannot imagine why or even how this is possible. 我看不到运行之间正在进行任何新的编译,而且我无法想象为什么甚至怎么可能。

Does anybody know this behavior? 有人知道这种行为吗? Or has at least a clue what is going on? 还是至少知道发生了什么?

Edit: In my example I would change the same source file that contains VERSION1 to get VERSION2. 编辑:在我的示例中,我将更改包含VERSION1的相同源文件以获得VERSION2。 I may, for example, fix a bug and run the code again, but it runs the old version with the bug. 例如,我可能修复了一个错误,然后再次运行代码,但是它运行的是带有该错误的旧版本。 Only when I run it a second time (without changing anything in the meantime) it runs the version without the bug. 仅当我第二次运行它(同时不进行任何更改)时,它才会运行没有错误的版本。

Edit3: It only happens sporadically. Edit3:它只是偶尔发生。 Most of the time Eclipse starts VERSION2 as expected, but sometimes, an older version of the code (that is, VERSION1) is started as if VERSION2 was never compiled. Eclipse在大多数情况下会按预期方式启动VERSION2,但有时会启动较旧版本的代码(即VERSION1),就像从未编译VERSION2一样。

First solution : 第一个解决方案:

In eclipse,click the little arrow next to the run button : 在Eclipse中,点击运行按钮旁边的小箭头:

在此处输入图片说明

And then you choose your version 2 .It will then be prioritized. 然后选择版本2

This is a little turnaround but who works well. 这是一个小转变,但谁做得很好。

2nd solution: 第二解决方案:

Click the same little arrow then: 单击相同的小箭头,然后:

  • Run configurations ... 运行配置...
  • Right Click on version 1 右键单击版本1
  • Delete 删除

Save your files and clean your project first. 保存文件并首先清理项目。 Then run it. 然后运行它。 Eclipse usually does some stupid stuff; Eclipse通常会做一些愚蠢的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM