简体   繁体   English

Java编译问题,Linux,Eclipse项目在Linux上重新编译

[英]Java compilation problem, Linux, project from Eclipse re-compile on Linux

I am trying to recompile an existing Java project exported from Eclipse. 我正在尝试重新编译从Eclipse导出的现有Java项目。 It is necessary to recompile this because I am running simulations remotely on other machines where a different (older) version of Java is installed. 有必要重新编译它,因为我在其他安装了不同(较旧)版本的Java的机器上远程运行模拟。 I have tried recompiling my .java file which specifies the simulation in question. 我已经尝试重新编译我的.java文件,该文件指定了有问题的模拟。 However, it appears that it is necessary to recompile all other classes etc as well. 但是,似乎有必要重新编译所有其他类等。 Has anyone got an idea how to do this WITHOUT using Eclipse (I am not the Admin on the other machines and thus Eclipse is unavailable to me) and not manually because the project is quite huge? 有没有人知道如何在不使用Eclipse的情况下这样做(我不是其他机器上的Admin,因此我不能使用Eclipse)而不是手动,因为项目非常庞大?

Thanks a lot for any suggestions! 非常感谢任何建议!

I recommend you to always have an command line way to build an application. 我建议您始终使用命令行方式来构建应用程序。 The usual way to do this in Java is using ANT (or Maven). 在Java中执行此操作的常用方法是使用ANT(或Maven)。

  1. As @Santiago Lezica says, Eclipse can generate an Ant file. 正如@Santiago Lezica所说,Eclipse可以生成一个Ant文件。

  2. I believe that Eclipse allows you to build for an older target platform than the one you are currently running. 我相信Eclipse允许您构建一个比您当前运行的目标平台更旧的目标平台。 That way you can do all of your builds locally. 这样您就可以在本地完成所有构建。

The second approach has the advantage that you can fix any problems arising from compiling for the older platforms (eg use of new language features, use of new classes / methods) from the comfort of your own ... workstation. 第二种方法的优点是,您可以在舒适的工作站中解决因编译旧平台而产生的任何问题(例如,使用新的语言功能,使用新的类/方法)。

There is another option that you should consider: Tell Eclipse to generate code for the old Java version (see the compiler options). 您还应该考虑另一个选项:告诉Eclipse为旧Java版本生成代码(请参阅编译器选项)。 That way, you can create code that runs on Java 1.3, even if Eclipse uses Java 5. 这样,即使Eclipse使用Java 5,您也可以创建在Java 1.3上运行的代码。

Not sure what your requirements are, but you could set the compiler level for your projects at the (older) level of your Linux installs. 不确定您的要求是什么,但您可以在Linux安装的(较旧)级别为项目设置编译器级别。 This would cause Eclipse to recompile it at that version, instead of a newer version. 这将导致Eclipse在该版本重新编译它,而不是更新版本。

At my company we use IBM's Rational Application Developer (instead of pure Eclipse), but I am assuming the option is in the same spot. 在我的公司,我们使用IBM的Rational Application Developer(而不是纯Eclipse),但我假设该选项位于同一位置。 If you right-click on your project, you can go to the Java Compiler options and then set the compatibility to the level of that on Linux (1.3, 1.4, etc.). 如果右键单击项目,可以转到Java Compiler选项,然后将兼容性设置为Linux(1.3,1.4等)上的兼容性。

Since compile Java byte-code is supposed to be portable (for the most part), this should get you past most of your problems. 由于编译Java字节代码应该是可移植的(大多数情况下),这应该可以让你解决大多数问题。

Otherwise, the other option is to use something like Ant or Maven scripts (which can be kicked off by Eclipse) and then just use a property to set the compiler right before you run it. 否则,另一个选择是使用Ant或Maven脚本(可以由Eclipse启动),然后在运行之前使用属性来设置编译器。 This way you don't have to switch properties on your projects all the time, if you truly do need "newer" compiled code and can't live with "older" code on both systems. 这样,如果您确实需要“更新”的编译代码并且无法在两个系统上使用“旧”代码,则无需始终在项目上切换属性。

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

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