Java 有没有办法找出类所在的maven工件?

Java 有没有办法找出类所在的maven工件?,java,spring,maven,dependencies,intellij-14,Java,Spring,Maven,Dependencies,Intellij 14,我正在尝试升级我们的Spring版本,并使用Spring IO平台BOM来实现这一点,但是我们的一些类已经丢失(移动到其他工件中),或者不再依赖于我所使用的某些东西。我试图找出它们最初是哪个包的一部分(一个例子是CSVStrategy)。其中一些依赖项,如WhitespaceTokenizer有十几个工件名称可以提供它,为了找到正确的升级路径,我需要找出它当前的来源。一种可能的方法是获取资源(类)位置。如果类来自一个jar文件,那么您至少可以得到jar名称。因此,您应该能够识别maven工件 s

我正在尝试升级我们的Spring版本,并使用Spring IO平台BOM来实现这一点,但是我们的一些类已经丢失(移动到其他工件中),或者不再依赖于我所使用的某些东西。我试图找出它们最初是哪个包的一部分(一个例子是CSVStrategy)。其中一些依赖项,如
WhitespaceTokenizer
有十几个工件名称可以提供它,为了找到正确的升级路径,我需要找出它当前的来源。

一种可能的方法是获取资源(类)位置。如果类来自一个jar文件,那么您至少可以得到jar名称。因此,您应该能够识别maven工件

someClass.getProtectionDomain().getCodeSource().getLocation().toURI();
或者使用ResourceLoader和logger,您可以打印classpath/servlet路径上所有类的列表

@Autowired 
ResourceLoader resourceLoader;

public void printResourceLocations() {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
    Resource[] resources = resolver.getResources("classpath*:com/**/*.class"));
    for (Resource resource : resources) {
        log.info(resource.getURI()); 
        // Not sure if that works, probably getFile() is ok?
    }
}    
我过去曾使用过这种类型的任务。我认为它不再被积极地维护了,但是它对我仍然有效。这是我使用的配置。注意,我不得不将它添加到我的POM的构建部分,尽管目标“报告”似乎暗示它是一个报告插件

<plugin>
  <groupId>org.jboss.tattletale</groupId>
  <artifactId>tattletale-maven</artifactId>
  <!-- The version of the plugin you want to use -->
  <version>1.2.0.Beta2</version>
  <executions>
    <execution>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
  <!-- This is the location which will be scanned for generating tattletale reports -->
    <source>${project.build.directory}/${project.artifactId}/WEB-INF/lib</source>
    <!-- This is where the reports will be generated -->
    <destination>${project.build.directory}/site/tattletale</destination>
  </configuration>
</plugin>

org.jboss.tattletale

. 我还没有机会使用它,它在我要调查的事情清单上。

search.maven.org有帮助吗?您可能还想阅读发行说明,它们应该提到(重新)移动的类。同样,没有帮助,因为我想知道我拥有什么,而不是我可能得到什么,提到的特定类似乎是一个间接依赖项或其他什么,除非我能弄清楚我正在使用的东西,否则我无法阅读发行说明。无论如何,Java不使用短类名,而是使用完全限定的类名,因此必须为该类提供一个声明包名的导入。在类路径中应该只有一个工件提供这个类。