2011-05-02 81 views
0

喜林试图从部署在JBoss的一个seassion豆行家索引搜索

此代码对JavaSE的

 PlexusContainer plexus = new DefaultPlexusContainer(); 

      NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class); 
      IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class); 

//   DefaultNexusIndexer n = new DefaultNexusIndexer(); 
       List 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); 

      Directory 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(
        "temp", 
        "test", 
        new File("/home/tomas/Desktop/mavenTest"), 
        tempIndexDirectory, 
        "http://repository.jboss.org/maven2/", 
        null, 
        indexCreators); 



       IndexUpdateRequest ur=new IndexUpdateRequest(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 request = new FlatSearchRequest(q); 
      FlatSearchResponse response = n.searchFlat(request); 


      for (ArtifactInfo a : response.getResults()) { 

       String bUrl=url+a.groupId+"/"+a.artifactId+"/"+a.version+"/"; 
       String fileName=a.artifactId+"-"+a.version; 
       System.out.println(bUrl+fileName+"."+a.packaging); 


      }

JBoss上搜索Maven仓库一个得到这个异常:

org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException 
     role: org.sonatype.nexus.index.NexusIndex

据我所知,这与构建路径无关,因为我可以实例化DefaultNexusIndexer(这不起作用,因为丛使他注射) 这可能是一些与丛

请帮

回答

0

你检查,你有你的类路径相同Plexus configuration files

我想,在你的SE测试你对其中包含的角色org.sonatype.nexus.index.NexusIndex这可能会在你的JBoss缺少组件描述符的类路径丛配置文件。

+0

我不以SE和在JBoss中使用同一个包有没有这个林的配置文件。 – sherif 2011-05-04 07:26:57

+0

编辑:org.sonatype.nexus.index.NexusIndex的描述符与类在同一个包中它可能是因为它被封装在耳朵文件中而不能找到它吗? – sherif 2011-05-04 07:35:47

+0

它应该可以从ear文件加载它,因为它只是使用[ClassLoader.getResources()](http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader。 html#getResources(java.lang.String)。也许你可以在你的JBoss上调试(或者添加日志记录)来查看它是否可以加载? – wjans 2011-05-04 07:51:39