2

我已经通过 Maven 在 eclipse 中导入了一些项目。我想在我的示例项目中访问该项目的方法。但是通常当我们想从某个项目中访问方法时,我们只需导入包并简单地访问该方法。

但是因为它是通过 Maven 导入的,所以它不是系统本地的。所以我决定,如果我将类路径设置为那个特定的项目/包,那么它可能会起作用。

我应该怎么做才能从中访问方法,或者我应该如何为其设置类路径?

如果您知道这一点,请尽快建议我。我从来没有在这种情况下工作过。

请指教

4

2 回答 2

3

The Maven plugin for eclipse will dynamically build the classpath for your projects based on their maven dependencies. Now, that classpath will be made up of your projects and, as @plucury says, what's in ~/.m2/repository.

If you want to follow methods and see the source implementation of the imported libraries, eclipse will work as usual (because it's just referencing jars from a different folder), but by default eclipse will not instruct maven to also download javadoc or source bundles for your classes. To do that, you need to set it in Windows>Preferences>Maven (Download Artifact Sources and Download Artifact Javadocs). In my experience, eclipse will not do that for already downloaded bundles, so you'll have to manually erase them from ~/.m2/repository and compile again. When eclipse downloads the jar, this time, it will also get the source, which will let you follow through.

于 2012-06-12T10:25:19.053 回答
0

Maven导入的jar包也存在于你的本地计算机上,我们称之为Local Repository。当你将项目导入eclipse时,你应该将classpath变量设置M2_REPO为你的Local Repository。默认情况下,路径是~/.m2/repository

于 2012-06-12T10:08:00.837 回答