问题
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?
回答1:
Just configure a classpath variable pointing to some DIR and give lib build path relative to that dir.
Or simply use Maven repository.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/5822717/trouble-working-on-java-app-between-windows-and-snow-leopard-machines