Maven 如何加载JSF2.2合同资源

Maven 如何加载JSF2.2合同资源,maven,jsf,jsf-2.2,resource-contracts,Maven,Jsf,Jsf 2.2,Resource Contracts,在我的maven项目中,我一直在尝试使用JSF2.2的契约加载css、js和图像文件资源,但除了无法加载消息之外,我什么都没有得到 以下是文件结构: src/main/webapp/* src/main/contracts/library-name/css/* src/main/contracts/library-name/js/* src/main/contracts/library-name/template.xhtml src/main/webapp/dev/index.xhtml 在我

在我的maven项目中,我一直在尝试使用JSF2.2的契约加载css、js和图像文件资源,但除了无法加载消息之外,我什么都没有得到

以下是文件结构:

src/main/webapp/*
src/main/contracts/library-name/css/*
src/main/contracts/library-name/js/*
src/main/contracts/library-name/template.xhtml
src/main/webapp/dev/index.xhtml
在我的faces-config.xml中,我有:

<resource-library-contracts>
     <contract-mapping>
        <url-pattern>/dev/*</url-pattern>
    <contracts>library-name</contracts>
    </contract-mapping>
</resource-library-contracts>
在我的index.xhtml中,我尝试了以下方法:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <f:view contracts="library-name">
        <ui:composition template="/template.xhtml">
            <ui:define name="content">
                <p>text</p> 
            </ui:define> 
    </ui:composition>
    </f:view>
</html>
以下是模板文件:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <h:outputScript name="js/script.js" />
        <h:outputStylesheet name="css/style.css" />
    </h:head>
    <h:body>
        <h1>Test</h1>
        <ui:insert name="content"/>
    </h:body>
</html>
编辑:以下是pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.Demos</groupId>
    <artifactId>MyProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>MyProject</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
             <groupId>javax.mail</groupId>
             <artifactId>mail</artifactId>
             <version>1.4.3</version>
        </dependency>
        <dependency>
            <groupId>net.coobird</groupId>
            <artifactId>thumbnailator</artifactId>
            <version>[0.4, 0.5)</version>
          </dependency>
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>1.2.1</version>
        </dependency>
        <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>16.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>
        <!--<dependency>
            <groupId>org.glassfish.main.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>4.0</version>
        </dependency>-->
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.10.1.1</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>com.paypal.sdk</groupId>
            <artifactId>rest-api-sdk</artifactId>
            <version>0.5.2</version>
        </dependency>     
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
我想写我尝试过的所有东西,但实际上这是几十种代码组合,比如在ui:content定义中使用h:outputScript h:outputStylesheet,使用带有EL引用的纯HTML,删除ui:composition,只使用一个页面等等

我已经尝试过将合同放在src/main/webapp/contracts文件夹中,但遇到了同样的问题

我的HTML输出总是正确的,但是生成的css链接标记返回一个RES_NOT_FOUND错误,脚本要么返回相同的结果,要么根本不显示。我正在尝试加载一个CSS/JS框架,所以我真的需要一个解决方案,可以模块化地处理所有这些成千上万的资产。我在网上找不到任何有效的东西,可能是因为合同比较新,但有什么问题吗?我的页面是否必须使用.jsf url映射?是否有类似于primefaces加载方式的方法从JAR文件加载这些资源?仅仅在服务器上上传资产并使用直接的html链接是否更有意义,因为它们都是前端资产


非常感谢您的帮助。

请将您的资源移到src/main/resources中。感谢您的回复!我之前没有提到这一点,因为我试图将主题限制在合同中,但当这些资源位于resources文件夹中时,我也遇到了类似的问题。据我所知,任何位于resources文件夹下不止一个目录的资源,即resources/js/bootstrap,而不仅仅是resources/js,都会导致此无法加载错误,这就是为什么我想知道它是否可能表示存在更大的问题。您能显示完整的pom文件吗?从答案移动到注释:请参阅。合同目录应位于src/main/webapp目录或中。你两个都没有。