Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:11:55+00:00 2026-05-28T18:11:55+00:00

What I’m trying to do is to write some Maven plugin which scans application

  • 0

What I’m trying to do is to write some Maven plugin which scans application classes looking for implementation of a particular interface (it might be classes with some annotation as well) and basis on the result generating some code. I’ve successfully implemented plugin running in the generate-sources phase and writing source code to the generated-sources directory.

The problem is with scanning classpath for the particular interface implementations/classes with some annotation.
I am using the Reflections library to scan classes in the following way:

private Set<Class< ? extends MyInterface >> scan(final String packageName) {
  final Reflections reflections = new Reflections(packageName);  
  return reflections.getSubTypesOf(MyInterface.class);
}

Unfortunately, this method returns empty set. When I print my classpath in the class extending org.apache.maven.plugin.AbstractMojo (the same within which I’m using Reflections) I get the following result:

/home/pd5108/apache-maven-2.2.1/boot/classworlds-1.1.jar

The classes I want to find using Reflections exists in dependend JARs as well as in the module within which plugin is configured. Looking at the classpath printed out it seems that at this point (generate-sources phase) dependencies defined in maven all not available on classpath yet – probably they are added in the next phases. Is that true? Is there any other approach I can use?

Here is the way how classpath is printed out:

URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();

for(int i=0; i< urls.length; i++) {
  System.out.println(urls[i].getFile());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:11:55+00:00Added an answer on May 28, 2026 at 6:11 pm

    Required MOJO class fields:

        /**
        * The project currently being built.
        *
        * @parameter expression="${project}"
        * @readonly
        * @required
        */
        private MavenProject project;
    
        /** @parameter expression="${localRepository}" */
        protected ArtifactRepository m_localRepository;
    
        /**@parameter default-value="${localRepository}" */
        private org.apache.maven.artifact.repository.ArtifactRepository
            localRepository;
    
        /** @parameter default-value="${project.remoteArtifactRepositories}" */
        private java.util.List remoteRepositories;
    
        /** @component */
        private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory;
    
        /** @component */
        private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
    

    Resolution of all dependencies JARs:

     final List<Dependency> dependencies = project.getDependencies();
    
        for (Dependency d : dependencies) {
    
            final Artifact artifact =
                artifactFactory.createArtifactWithClassifier(d.getGroupId(),
                    d.getArtifactId(), d.getVersion(), d.getType(),
                    d.getClassifier());
    
            try {
                resolver.resolve(artifact, remoteRepositories,
                        localRepository );
            } catch (ArtifactResolutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ArtifactNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            File artifactFile = artifact.getFile();
            System.out.println(artifactFile.getAbsolutePath());
        }
    

    And now we need to scan these JARs using reflection API looking for the appropriate classes.
    At this point I think that there’s no other way, since I work in generate-sources phase and artifact values for the next phases are not computed yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.