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

  • SEARCH
  • Home
  • 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 8185629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:55:04+00:00 2026-06-07T01:55:04+00:00

I’ve written a custom maven reporting plugin to output some basic information about spring-mvc

  • 0

I’ve written a custom maven reporting plugin to output some basic information about spring-mvc classes. In my internal tests I can see that code like this :

public Set<Class<?>> findControllerClasses(File buildOutputDir) throws IOException, ClassNotFoundException {

    Collection<URL> urls = ClasspathHelper.forJavaClassPath();
    if (buildOutputDir != null) {
        urls.add(buildOutputDir.toURI().toURL());
    }

    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(urls));
    Set<Class<?>> types = reflections.getTypesAnnotatedWith(Controller.class);
    return types;
}

Works well at pulling in annotated classes. However, when I use the reporting plugin in another project, annotated classes are not picked up.

Can someone shed some light on how to access the compiled classes for reporting purposes? Or whether this is even possible ??

EDIT : partially solved using the answer to: Add maven-build-classpath to plugin execution classpath

However, this only loads classes if they have no dependencies outside the runtimeClasspathElements var for maven. Is there any way to merge these classes in to the classrealm too ?

  • 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-06-07T01:55:06+00:00Added an answer on June 7, 2026 at 1:55 am

    Ok. Expanding on the answer in the above comment, the full solution is to use a Configurer that takes into account both the runtime classpath AND the urls from the poms dependencies. Code shown below

    /**
     * 
     * @plexus.component 
     *                   role="org.codehaus.plexus.component.configurator.ComponentConfigurator"
     *                   role-hint="include-project-dependencies"
     * @plexus.requirement role=
     *                     "org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup"
     *                     role-hint="default"
     * 
     */
    public class ClassRealmConfigurator extends AbstractComponentConfigurator {
    
        private final static Logger logger = Logger.getLogger(ClassRealmConfigurator.class.getName());
    
        public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener) throws ComponentConfigurationException {
    
            addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm);
    
            converterLookup.registerConverter(new ClassRealmConverter(containerRealm));
    
            ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter();
    
            converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener);
        }
    
        private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException {
            Set<String> runtimeClasspathElements = new HashSet<String>();
            try {
                runtimeClasspathElements.addAll((List<String>) expressionEvaluator.evaluate("${project.runtimeClasspathElements}"));
    
            } catch (ExpressionEvaluationException e) {
                throw new ComponentConfigurationException("There was a problem evaluating: ${project.runtimeClasspathElements}", e);
            }
    
            Collection<URL> urls = buildURLs(runtimeClasspathElements);
            urls.addAll(buildAritfactDependencies(expressionEvaluator));
            for (URL url : urls) {
                containerRealm.addConstituent(url);
            }
        }
    
        private Collection<URL> buildAritfactDependencies(ExpressionEvaluator expressionEvaluator) throws ComponentConfigurationException {
            MavenProject project;
            try {
                project = (MavenProject) expressionEvaluator.evaluate("${project}");
            } catch (ExpressionEvaluationException e1) {
                throw new ComponentConfigurationException("There was a problem evaluating: ${project}", e1);
            }
            Collection<URL> urls = new ArrayList<URL>();
            for (Object a : project.getArtifacts()) {
                try {
                    urls.add(((Artifact) a).getFile().toURI().toURL());
                } catch (MalformedURLException e) {
                    throw new ComponentConfigurationException("Unable to resolve artifact dependency: " + a, e);
                }
            }
            return urls;
        }
    
        private Collection<URL> buildURLs(Set<String> runtimeClasspathElements) throws ComponentConfigurationException {
    
            List<URL> urls = new ArrayList<URL>(runtimeClasspathElements.size());
            for (String element : runtimeClasspathElements) {
                try {
                    final URL url = new File(element).toURI().toURL();
                    urls.add(url);
                } catch (MalformedURLException e) {
                    throw new ComponentConfigurationException("Unable to access project dependency: " + element, e);
                }
            }
    
            return urls;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.