嗨,我正在尝试从部署在 jboss 上的 seassion bean 中搜索 maven 存储库
此代码适用于 javaSE
PlexusContainer plexus = new DefaultPlexusContainer();
NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class);
IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class);
// DefaultNexusIndexer n = new DefaultNexusIndexer();
列出 indexCreators=new ArrayList();
// IndexingContext c = n.addIndexingContext("test", "test",new File("/home/tomas/Desktop/test"),new File("/home/tomas/Desktop/index"), "http: //repository.jboss.org/", null);
目录 tempIndexDirectory = new RAMDirectory();
// IndexCreator min = new MinimalArtifactInfoIndexCreator();
// MavenPluginArtifactInfoIndexCreator mavenPlugin = new MavenPluginArtifactInfoIndexCreator();
// MavenArchetypeArtifactInfoIndexCreator mavenArchetype = new MavenArchetypeArtifactInfoIndexCreator();
// JarFileContentsIndexCreator jar = new JarFileContentsIndexCreator();
//
IndexCreator min = plexus.lookup(IndexCreator.class, MinimalArtifactInfoIndexCreator.ID);
IndexCreator mavenPlugin = plexus.lookup(IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID);
IndexCreator mavenArchetype = plexus.lookup(IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID);
IndexCreator jar = plexus.lookup(IndexCreator.class, JarFileContentsIndexCreator.ID);
indexCreators.add(min);
indexCreators.add(mavenPlugin);
indexCreators.add(mavenArchetype);
indexCreators.add(jar);
IndexingContext c = n.addIndexingContext(
“温度”,
“测试”,
新文件(“/home/tomas/Desktop/mavenTest”),
临时索引目录,
"http://repository.jboss.org/maven2/",
空值,
索引创建者);
索引更新请求 ur=新索引更新请求(c);
ur.setForceFullUpdate(true);
iu.fetchAndUpdateIndex(ur);
// for (String s : c.getAllGroups()) {
// System.out.println(s);
// }
BooleanQuery q = new BooleanQuery();
q.add(n.constructQuery(ArtifactInfo.GROUP_ID, "*"), Occur.SHOULD);
FlatSearchRequest 请求 = 新的 FlatSearchRequest(q);
FlatSearchResponse 响应 = n.searchFlat(request);
for (ArtifactInfo a : response.getResults()) {
字符串 bUrl=url+a.groupId+"/"+a.artifactId+"/"+a.version+"/";
字符串文件名=a.artifactId+"-"+a.version;
System.out.println(bUrl+fileName+"."+a.packaging);
}
在 jboss 上得到这个异常:
org.codehaus.plexus.component.repository.exception.ComponentLookupException:java.util.NoSuchElementException
角色:org.sonatype.nexus.index.NexusIndex
据我所知,这与构建路径无关,因为我可以实例化 DefaultNexusIndexer(这不起作用,因为 plexus 必须进行注射)这可能与 plexus 有关
请帮忙