【问题标题】:CXF- FileNotFoundException with Maven and Tomcat 7CXF-FileNotFoundException 与 Maven 和 Tomcat 7
【发布时间】:2013-06-20 13:13:26
【问题描述】:

我尝试在 Tomcat 7 中运行一个网络应用程序。我正在使用 Maven,并且使用 jetty-Plugin 一切正常。在构建战争并将其部署到 Tomcat7 时,我得到 Keystore-File 的 FileNotFoundException。

在 cxfClient.xml 中我必须将文件放在哪里以及我必须使用什么路径?

pom.xml 片段:

            <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-xjc-plugin</artifactId>
            <version>2.3.2</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xsdtojava</goal>
                    </goals>
                    <configuration>
                        <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                        <xsdOptions>
                            <xsdOption>
                                <xsd>${basedir}/src/main/resources/xsd/template1.xsd</xsd>
                                <packagename>some.packagename</packagename>
                            </xsdOption>
                        </xsdOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>2.7.3</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <!-- <wsdl>URLTOWSDL</wsdl> -->
                                <wsdl>${basedir}/src/test/resources/somewsdl.wsdl</wsdl>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

cxfClient.xml:

      <sec:keyManagers>
      <sec:keyStore file="truststore.jks" password="test1234" type="JKS"/>
  </sec:keyManagers>
  <sec:trustManagers>
      <sec:keyStore file="truststore.jks" password="test1234" type="JKS"/>
  </sec:trustManagers>

日志文件中的行:

Error creating bean with name 'servicename.http-conduit': Cannot create inner bean '(inner bean)' of type [org.apache.cxf.configuration.jsse.TLSClientParametersConfig] while setting bean property 'tlsClientParameters'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static java.lang.Object org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParameters(java.lang.String)] threw exception; nested exception is java.lang.RuntimeException: java.io.FileNotFoundException: src\main\resources\truststore.jks (Das System kann den angegebenen Pfad nicht finden)

我在 cxfClient 中尝试了使用不同路径的 src/main/resources、src/main/webapp,但总是得到 FileNotFoundException。

提前致谢

【问题讨论】:

  • 默认不需要keystore文件,这是什么keystore文件?堆栈跟踪也不会受到伤害。
  • 我看到你更新了问题:) 定义 jks 文件的绝对路径,否则它必须位于类路径的根目录中(WEB-INF/classes,即src/main/resources)。 cxf-client.xml 通常在META-INF 中,所以它可能必须在那个文件夹中,如果它是相对于 xml 的。
  • 已经试过了 :( 我已将 cxfClient.xml 和 truststore.jks 放入 src/main/resources。我在 tomcat-Folder 的 WEB-INF/classes 中看到它们。我设置了“ file="src/main/resources/truststore.jks"。但仍然得到异常...
  • 现在这是一个问题 :) 如果你把它们放在那里,那么它们将被复制到类路径的根目录,这意味着下面的设置应该可以工作file="truststore.jks"
  • 这是我之前的设置(你可以在上面的代码中看到)。我使用mvn clean tomcat7:deploy 进行部署,我在WEB-INF/classes 中看到了文件,我得到了异常。当我使用mvn jetty:run 时,一切都按预期工作..

标签: java maven tomcat cxf filenotfoundexception


【解决方案1】:

密钥库(由上面的 sec:keyStore 元素标识)可以是 通过以下三种方式中的任何一种进行识别:通过文件、资源或 url 属性。文件位置是绝对路径或相对于 工作目录,资源属性是相对于 类路径,并且 URL 必须是有效的 URL,例如“http://...” “file:///...”等只有“url”、“file”或“resource”的一个属性 是允许的。

来源:http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html

【讨论】:

  • &lt;sec:keyStore resource="truststore.jks" password="test1234" type="JKS"/&gt;“资源”而不是“文件”是要走的路
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 1970-01-01
  • 2019-12-03
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
相关资源
最近更新 更多