在 Windows 和 Snow Leopard 计算机之间使用 Java 应用程序时遇到问题
必须有一个简单的解决方案来解决这个问题,但我在 Windows 机器和 Snow Leopard 机器上处理 Java 应用程序时遇到了麻烦。我在 Eclipse 中进行所有开发,并通过 SVN 签入/签出传输代码。我遇到的问题是应用程序引用了一堆 Snow Leopard JDK jar,并通过类路径中的绝对位置引用它们。有人有在这种环境下工作的经验吗?你是如何解决这个问题的?
There has got to be a simple solution to this, but I'm having trouble working on a Java application on a Windows machine and a Snow Leopard machine. I'm doing all of my development in Eclipse and transferring the code via SVN checkins/checkouts. The problem I'm having is the application references a bunch of Snow Leopard JDK jars and refers to them via an absolute location in the classpath. Does anybody have experience working in this type of environment and how do you get around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需配置一个 类路径变量指向某个DIR并给出相对于该目录的lib构建路径。
或者简单地使用 Maven 存储库。
Just configure a classpath variable pointing to some DIR and give lib build path relative to that dir.
Or simply use Maven repository.
而不是使用绝对路径、路径变量、maven、ivy 或其他...
首选项 -> Java->安装的 JRE
选择用于您的项目的 JRE 并点击编辑。添加 JDK 中的其他 jar。就是这样。所有项目都将看到更改后的 JRE 定义。由于此设置保留在工作区中,因此在不同操作系统上以不同方式配置它不会有任何问题。
Rather than using absolute paths, path variables, maven, ivy or whatever...
Preferences -> Java -> Installed JREs
Select the JRE that is used for your projects and hit edit. Add other jars from your JDK. That's it. All projects will see the changed JRE definition. Since this setting is kept in the workspace, you will not have any issue configuring it differently on different operating systems.
如果您的外部 jar 文件作为项目的一部分位于 war/WEB-INF/lib 目录中,如果您进入“配置构建路径”并将它们添加为外部 jar 文件,那么它们将使用完整限定路径添加,这不是您所希望的。想。如果您在两个环境上具有相同的文件结构,您就不会问这个问题。
如果您打开项目中实际的 war/WEB-INF/lib 目录,然后右键单击 jar 并选择“构建路径/添加到构建路径”,则 jar 文件将添加相对路径。这些问题将在 Windows 和 OSX 上得到解决。如果该文件已在构建路径中配置,您将不会获得“添加”选项。
您还可以通过手动编辑项目的 .classpath 文件来实现相同的目的,以使引用相对,但这样您就不需要 IDE。
这不适用于像 servlet-api.jar 这样的库,它随 Tomcat 一起提供,并且通常安装在 OSX 和 Windows 上的不同位置,并且您不希望将其作为 war 文件的一部分。我在 Windows 上将 Tomcat 安装在与 OSX 相同的目录 (/Library) 中,这似乎有效。至少我可以在 OSX 上提交一个项目并更新到 Windows,它仍然可以工作。
If your external jar files are in a war/WEB-INF/lib directory as part of your project, if you go into Configure Build Path and add them as external jar files they are added using a full qualified path, which is not what you want. If you had the same file structures on both environments you wouldn't have asked this question.
If you open the actual war/WEB-INF/lib directory in your project and right click on the jars and select "Build Path/Add to build path" then the jar files are added with a relative path. These will be resolved across Windows and OSX. If the file is already configured in the build path you will not get the Add option.
You can also achieve the same thing by manually editing the .classpath file for the project to make the reference relative but then you wouldn't need an IDE.
This doesn't work for a library like servlet-api.jar which comes with Tomcat and is typically installed in different places on OSX and Windows and you don't want as part of your war file. I installed Tomcat on Windows in the same directory (/Library) as for OSX and that seems to work. At least I can commit a project on OSX and update to Windows and it still works.