简体   繁体   English

如何使用Eclipse生成的.classpath文件指定外部库?

[英]How to use Eclipse generated .classpath file to specify the external libraries?

I need to start a Java application using a .bat file . 我需要使用.bat文件启动Java应用程序。 Here is what I have so far, and it works fine 这是我到目前为止的内容,并且工作正常

java  -cp ".;C:\someLibrary.jar;C:\someLibrary.jar;..." Main 

The problem is there are too many external libraries, and Eclipse already generates a .classpath file referring to all those libraries. 问题是外部库太多,Eclipse已经生成了一个引用所有这些库的.classpath文件。 Is there any way I could use that Eclipse generated .classpath file in my batch, so that I don't have to list all the libraries in the java command above ? 有什么办法可以在我的批处理中使用Eclipse generated .classpath文件,从而不必在上面的java命令中列出所有库?

Can I use something like this 我可以用这样的东西吗

java  -cp ".;C:\ ..\pathToEclipseFolder.classpath" Main 

The reason I am asking this is because I will eventually end up updating some of those external libraries. 我之所以这样问,是因为我最终将要更新其中一些外部库。 And I want to still be able to use the original .bat file 而且我仍然希望能够使用原始的.bat文件

If your Java application needs the libraries, then you must specify them in the classpath of your .bat file. 如果您的Java应用程序需要这些库,则必须在.bat文件的类路径中指定它们。

A couple of considerations: 有两个注意事项:

1) Maybe you have more libraries listed in your Eclipse classpath than you actually need 1)也许您在Eclipse类路径中列出了比实际需要更多的库

2) Java6 and higher allows you to specify a directory , instead of requiring you to specify each individual library in that directory: 2)Java6和更高版本允许您指定目录 ,而不需要您指定该目录中的每个库:

java -classpath ".;c:\\mylib\\*" MyApp

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

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