1

My Question is near the same than Packaging Facelets files (templates, includes, composites) in a JAR. Wich was full quallyfied awnsered by BalusC.

But I'll go a bit farther. Since JBoass AS 7 the ClassLoading in JB has changed. Now there is a strict Modul-ClassLoading and it works so far ;)

I have a WAR-file with an jboss-deployment-structure.xml plus one JAR-file with some CDI-Beans and xhtml-files in /META-INF/resources/modul. I deploy the two "projects" seperately (so the JAR is not packaged into the WAR both ar copyed in JBOSS_HOME/standalone/deployment).

The WAR references the JAR as a Modul through the jboss-deployment-structure.xml.

I'm able to Inject CDI-Beans from the JAR but I can't reach the xhtml-files in /META-INF/resources/modul/. Everytime I try to load CONTEXT_ROOT/modul/modul.xhtml I get a warning from JB :

[javax.enterprise.resource.webcontainer.jsf.application] (default task-5) JSF1064: Ressource /modul/modul.xhtml can not be found or served.

If I package the JAR into the WAR (WEB-INF/lib) it dosen't work ither.

I provided a faces-config.xml under META-INF/resources

Did I miss somethink?

reggards

I use WildFly 9.0.1 Final and the Provided J2EE implementations.

Community
  • 1
  • 1
  • @MahendranAyyarsamyKandiar thanx for your comment. Unfortunately thats not the solution. But i found one, I'll awnser soon. – David Witte Dec 17 '15 at 23:28

1 Answers1

0

I found a solution. The problem is, that JBoss doesn't scan the JAR if it is not packaged in WEB-INF/lib.

In my initial question I have wrote "If I package the JAR into the WAR (WEB-INF/lib) it doesn't work ither." thats not true i just didn't recognise that i placed my files in /META-INF/modul instead of /META-INF/resources/modul. I moved the files and it start to work if i placed the JAR in WEB-INF/lib.

But the problem with an separate deployment still persisted.

Now I use an custom ResourceHandler (JSF 2.2 way) and it work like a charm.

All my moduls have to implement a interface. In that way I'm able to Inject all these instances by CDI. Now i itterate over all moduls and look for my resource. The ResourceHandler is placed in the WAR not in the single JAR's. In that way i just have to implement it onetimes.

Here is my code example:

    public class ExternalResourceHandler extends ResourceHandler {

@Inject
@Any
Instance<ModulDescriptor> moduls;

private ResourceHandler parent;
private String basePath = "META-INF/resources";

public ExternalResourceHandler() {
}

public ExternalResourceHandler(ResourceHandler parent) {
    this.parent = parent;
}

@Override
public ViewResource createViewResource(FacesContext context, String resourceName) {

    System.out.println("Invoked for: " + resourceName);

    ViewResource resource = parent.createViewResource(context, resourceName);

    if (resource == null) {
        System.out.println("Parent failed");
        if (moduls != null) {
            for (ModulDescriptor mod : moduls) {
                URL url = mod.getClass().getClassLoader().getResource(basePath + resourceName);
                if (url != null) {
                    return new ViewResource() {
                        @Override
                        public URL getURL() {
                            return url;
                        }
                    };
                }
            }
        } else {
            System.out.println("INJECTION IS NULL");
        }
    }

    return resource;
}   
//followed by all other overriden methods wich return null ;)
}

Thanks to @BalusC for this awnser wich does the clue in the second step.

Community
  • 1
  • 1