0

Hi Im trying to search a maven repository from a seassion bean deployed on jboss

this code works on 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);


            }

On jboss a get this exception :

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

As far as I know this has nothing to do with the build path because i can instantiate the DefaultNexusIndexer (which does not work because plexus hast to make his injections) It is probably something with plexus

Please help

carlspring
  • 31,231
  • 29
  • 115
  • 197
sherif
  • 2,282
  • 19
  • 21

2 Answers2

1

this one works

https://github.com/cstamas/maven-indexer-examples/tree/master/indexer-example-01 btw its the newest version

sherif
  • 2,282
  • 19
  • 21
0

Have you checked that you have the same Plexus configuration files on your classpath?

I suppose that in your SE test you do have a plexus configuration file on the classpath which contains a component descriptor for role org.sonatype.nexus.index.NexusIndex which might be missing on your JBoss.

wjans
  • 10,009
  • 5
  • 32
  • 43
  • I dont have this configuration files in neither Im using the same package in SE and in jboss. – sherif May 04 '11 at 07:26
  • EDIT :The descriptor for org.sonatype.nexus.index.NexusIndex is in the same package as the class Can it be that plexus cant find it because it is packaged in a ear file ? – sherif May 04 '11 at 07:35
  • It should be possible to load it from an ear file as well since it just uses [ClassLoader.getResources()](http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResources(java.lang.String). Maybe you can debug (or add logging) on your JBoss to see if it can be loaded? – wjans May 04 '11 at 07:51