java - 服务器没有从我的 war 中引用我的依赖 jar,但是当我将相同的 jar 放在服务器库中时它工作正常

标签 java maven tomcat jar war

我正在 Netbeans8.0 IDE、apache-tomcat 服务器上开发一个 java web 应用程序。

我有三个项目,其中一个有父 pom.xml,另外两个有自己的 POM.xml 此应用程序具有遗留代码,并且在运行时它引用服务器库中的 ojdbc6 jar。现在管理层要我们把所有的依赖jar移到war的Web-Inf/lib

我们已将 jars 下载到应用程序的本地文件夹中,但出于某种原因,当我将它们移动到 pom.xml 时,它没有从 Web-INF 中引用,我认为我可能是错误的组和 artifactID。所以我直接从 codeIds maven 存储库引用它,现在我有两个问题 1. 只有当我使用依赖构建时,我才会在 Web-Inf 中看到这个 jar 2. 在 Web-Inf 中看到它后,当我调试或运行它时,我在运行时遇到 ojdbc-driver 异常。

但是当我将同一个 jar 移动到 server/lib 时,它工作正常。

我花了几乎整整一周的时间在互联网上的许多文档的帮助下解决了这个问题,但没有运气。

我的 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>portalsGroupId.portals</groupId>
    <artifactId>matrix</artifactId>
    <name>matrix</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <url>http://www.8x8.com</url>

    <parent>
        <groupId>portalsGroupId</groupId> 
        <artifactId>portals</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <repositories>
        <repository>
            <id>codelds</id>
            <url>https://code.lds.org/nexus/content/groups/main-repo</url>
        </repository>
        <repository>
            <id>jboss-public-repository-group</id>
            <name>Jboss Repository for Maven</name>
        <url><http://repository.jboss.org/nexus/content/groups /public></url>
        </repository>

        <repository>
            <id>jboss</id>
            <name>Jboss</name>
            <url>http://repository.jboss.com/maven2/</url>
        </repository>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>http://8x8.com/nexus/content/groups/public-jboss/</url>
            <layout>default</layout>
            <releases>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <org.richfaces.bom.version>4.0.0.Final</org.richfaces.bom.version>        
        <slf4j.version>1.5.6</slf4j.version>
        <jsf.version>2.1.2</jsf.version>
        <ssputil.version>1.0-SNAPSHOT</ssputil.version>
        <sspapi.version>1.0-SNAPSHOT</sspapi.version>        
        <oltu.version>1.0.0</oltu.version>
    </properties>

    <build>
        <finalName>matrix-${project.version}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1-alpha-2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/java</directory>
                            <targetPath>/WEB-INF/src</targetPath>
                        </resource>
                    </webResources>
                    <webResources>
                        <resource>
                            <directory>${basedir}/../ext_lib/cloud/</directory>
                            <targetPath>/WEB-INF/lib</targetPath>
                        </resource>
                        <resource>
                            <directory>${basedir}/../ext_lib/commons-net/</directory>
                            <targetPath>/WEB-INF/lib</targetPath>
                        </resource>
                        <resource>
                            <directory>${basedir}/src/main/java/com/_8x8/matrix/skin/</directory>
                            <targetPath>/WEB-INF/classes</targetPath>
                        </resource>
                        <resource>
                            <directory>${basedir}/../ext_lib/httpclient431/</directory>
                            <targetPath>/WEB-INF/lib</targetPath>
                        </resource>
                    </webResources>          
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>jee6</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <configuration>
                            <webappDirectory>${project.build.directory}/${project.build.finalName}-jee6</webappDirectory>
                            <packagingExcludes>WEB-INF/lib/jsf-api*,WEB-INF/lib/jsf-impl*,WEB-INF/lib/jstl*</packagingExcludes>
                            <warSourceExcludes>WEB-INF/lib/jsf-api*,WEB-INF/lib/jsf-impl*,WEB-INF/lib/jstl*</warSourceExcludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>


            <dependencyManagement>  
                <dependencies>  
                    <dependency>  
                        <groupId>org.richfaces</groupId>  
                        <artifactId>richfaces-bom</artifactId>  
                        <version>${org.richfaces.bom.version}</version>  
                        <scope>import</scope>  
                        <type>pom</type>  
                    </dependency>  
                </dependencies>  
            </dependencyManagement> 

            <dependencies>
                <dependency>  
                    <groupId>org.richfaces.ui</groupId>  
                    <artifactId>richfaces-components-ui</artifactId>  
                </dependency>  
                <dependency>  
                    <groupId>org.richfaces.core</groupId>  
                    <artifactId>richfaces-core-impl</artifactId>  
                </dependency>  
                <dependency>
                    <groupId>com.sun.faces</groupId>
                    <artifactId>jsf-api</artifactId>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.oltu.oauth2</groupId>
                    <artifactId>org.apache.oltu.oauth2.client</artifactId>
                    <version>${oltu.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.faces</groupId>
                    <artifactId>jsf-impl</artifactId>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>javax.transaction</groupId>
                    <artifactId>jta</artifactId>
                    <version>1.1</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>jee6</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>war</goal>
                                </goals>
                                <configuration>
                                    <webappDirectory>${project.build.directory}/${project.build.finalName}-jee6</webappDirectory>
                                    <classifier>jee6</classifier>
                                    <packagingExcludes>WEB-INF/lib/jsf-api*,WEB-INF/lib/jsf-impl*,WEB-INF/lib/jstl*</packagingExcludes>
                                    <warSourceExcludes>WEB-INF/lib/jsf-api*,WEB-INF/lib/jsf-impl*,WEB-INF/lib/jstl*</warSourceExcludes>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <webResources>
                                <resource>
                                    <directory>${basedir}/src/main/java</directory>
                                    <targetPath>/WEB-INF/src</targetPath>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.5</version>
            </dependency>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>matrix_ssp_api</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.richfaces</groupId>
                <artifactId>richfaces-bom</artifactId>
                <version>${org.richfaces.bom.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>${jsf.version}</version>
            </dependency>
            <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
            <version>7.0.19</version>
            <type>jar</type>
        </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>4.2.0.Final</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.2.0.1.0</version>
                <type>jar</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.richfaces.ui</groupId>
            <artifactId>richfaces-components-ui</artifactId>
            <version>${org.richfaces.bom.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.oltu.oauth2</groupId>
            <artifactId>org.apache.oltu.oauth2.client</artifactId>
            <version>${oltu.version}</version>
        </dependency>
        <dependency>
            <groupId>org.richfaces.core</groupId>
            <artifactId>richfaces-core-impl</artifactId>
            <version>${org.richfaces.bom.version}</version>
        </dependency>
        <dependency>
            <groupId>org.richfaces.cdk</groupId>
            <artifactId>annotations</artifactId>
            <scope>provided</scope>
            <version>${org.richfaces.bom.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <!--scope>provided</scope-->
        </dependency>        
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
        </dependency>

        <!-- Local Project Dependency -->
        <dependency>
            <groupId>portalsGroupId.portals</groupId>
            <artifactId>matrix_ssp_util</artifactId>
            <version>1.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>com._8x8.matrix</groupId>
                    <artifactId>matrix_httpClient401_cmncodec</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>portalsGroupId.portals</groupId>
            <artifactId>matrix_ssp_api</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com._8x8.matrix</groupId>
                    <artifactId>matrix_httpClient401_cmncodec</artifactId>
                </exclusion>
            </exclusions>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>portalsGroupId.portals</groupId>
            <artifactId>matrix_cloud_commons</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/cloud/cloud_commons.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>portalsGroupId.portals</groupId>
            <artifactId>matrix_cloud_client</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/cloud/cloud_client.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/commons-net/commons-net-3.0.1.jar</systemPath>
        </dependency>  

        <dependency>
            <groupId>sims</groupId>
            <artifactId>sims</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/sims/sims-connector.jar</systemPath>
        </dependency>  

        <dependency>
            <groupId>jlayer</groupId>
            <artifactId>jlayer</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/jlayer/jl1.0.1.jar</systemPath>
        </dependency>  

        <dependency>
            <groupId>cdirector</groupId>
            <artifactId>cdirector</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/chartdirector/ChartDirector.jar</systemPath>
        </dependency>  

        <dependency>
            <groupId>gson</groupId>
            <artifactId>gson222</artifactId>
            <scope>system</scope>
            <version>1.0-SNAPSHOT</version>
            <systemPath>${project.basedir}/../ext_lib/gson/google-gson-2.2.2/gson-2.2.2.jar</systemPath>
        </dependency>    
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.5</version>
        </dependency>  
        <dependency>
            <groupId>org.codehaus.jettison</groupId>
            <artifactId>jettison</artifactId>
            <version>1.3.4</version>
        </dependency>  
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
    </dependencies>
</project>

最佳答案

只是下载一个 jar 并将其放入项目文件夹并不是“maven 方式”...

如果您想使用不在中央仓库中的库,您必须将其放入本地仓库或使用另一个远程仓库。 如果我理解正确,您选择使用 code.lds.org repo 。 我在您的 pom 中看不到的是(真正的)依赖项。只有 dependency management对于 ojdbc6 .

你得给你加这个<dependencies>节并运行 mvn package (或在 Netbeans build 中)和 ojdbc6 jar 应该打包到 war 中。

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
</dependency>

(此处跳过版本,因为它已在 <dependencyManagement> 中定义;不需要 <type>jar</type>,因为它是默认值...)

你也可以看看这个问题,也许还有更多/其他信息:Oracle JDBC ojdbc6 Jar as a Maven Dependency

关于java - 服务器没有从我的 war 中引用我的依赖 jar,但是当我将相同的 jar 放在服务器库中时它工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39525263/

相关文章:

java - 从系统变量值读取 logback.xml

java - 单个 tomcat 和 postgres 实例上的多个应用程序?

java - 桌面应用程序中的 spring 验证

java - 扫描仪调试

java - 如何从 JUnit 内部使用 Voldemort 服务器?

java - ClassNotFoundException 尽管 list 类路径包含包含该类的 .jar

apache - 无法在 HTTPD.CONF 文件中配置 mod_JK 以实现负载平衡

java - 查找哪个依赖项包含 Spring WebApplicationInitializer

java - Selenium,在使用 Java 运行 chrome 测试时创建简单的对话框

java - Spring:无法导入库