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 1079223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:50:15+00:00 2026-05-16T21:50:15+00:00

As far as I know, for using @Annotations (or [Attributes] in C#) you have

  • 0

As far as I know, for using @Annotations (or [Attributes] in C#) you have to have a reference to the class metadata, so that you can ask if the class is annotated (attributed) or not.

My question is how does JSF implementation find all classes annotated with @ManagedBean? Does it scan all of the classes in the class path? Or is there a way to actually “query” the JVM for the annotated classes?

I’m asking this because when I put my annotated backing beans in my web project directly, there’s no problem. But the beans that I define in the JAR files (to be reusable across projects) are not registered. Is there something that I have to tell MyFaces to direct it which JAR files to look at?

Also, using annotations introduce many nice patterns of programming. I want to know if I can find all annotated classes somehow…

  • 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-16T21:50:15+00:00Added an answer on May 16, 2026 at 9:50 pm

    My question is how does JSF implementation find all classes annotated with @ManagedBean? Does it scan all of the classes in the class path? Or is there a way to actually "query" the JVM for the annotated classes?

    Start by peeking around in com.sun.faces.application.annotation.AnnotationManager in Mojarra sources. Note that this is not part of the API, but implementation-specific.

    If you intend to use such tools for your own projects, I recommend using Reflections for this instead of homegrowing it.

    Set<Class<?>> classes = reflections.getTypesAnnotatedWith(SomeAnnotation.class);
    

    In a Java EE environment, better yet is to use CDI instead.


    I’m asking this because when I put my annotated backing beans in my web project directly, there’s no problem. But the beans that I define in the JAR files (to be reusable across projects) are not registered. Is there something that I have to tell MyFaces to direct it which JAR files to look at?

    To have JSF to load any annotated managed beans from a JAR file, you have to put a /META-INF/faces-config.xml file in the JAR file. Just a JSF 2.0 compatible <faces-config> declaration is sufficient to get the JSF scan the JAR file for any interesting annotated classes. If the /META-INF/faces-config.xml file is not present in the JAR file, then JSF won’t scan the JAR file to improve loading performance.

    Here’s how a minimum JSF 2.0 compatible faces-config.xml file look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
        version="2.0">
    </faces-config>
    

    Store it in the META-INF folder of the JAR.

    This is by the way described in chapter 11.4.2 of JSF 2.0 specification.

    11.4.2 Application Startup Behavior

    …

    This algorithm provides considerable flexibility for developers that are assembling the components of a JSF-based web
    application. For example, an application might include one or more custom UIComponent implementations, along with
    associated Renderers, so it can declare them in an application resource named “/WEB-INF/faces-config.xml”
    with no need to programmatically register them with Application instance. In addition, the application might choose
    to include a component library (packaged as a JAR file) that includes a “META-INF/faces-config.xml” resource.

    The existence of this resource causes components, renderers, and other JSF implementation classes that are stored in this
    library JAR file to be automatically registered, with no action required by the application.

    See also:

    • Structure for multiple JSF projects with shared code
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I know that FileSystemWatcher can look into a folder and if any
As far as I know, support library is using because old devices don't have
As far as I know, mysql doesn't use index if using IN(1, 2...n) queries.
I've been using Webservices so long. But,so far up to what I know,I haven't
As far as I know that JSF keeps all the session scoped bean in
I am using VS2008, and ASP.NET 3.5 C# I have an array list that
As far as I know, there are many applications using SIP : ekiga, linphone,
I'm using PHPMailer for sending activation codes to users. As far as I know,
I'm using IntelliJ Idea 11.1.1 (newest version as far as I know) on Windows
i want to ask why are the java annotations used so much... I know

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.