如何将jar文件添加到项目中,而不是添加到Tomcat lib文件夹中?

时间:2018-10-09 13:41:44

标签: java tomcat

通过这个github项目,我将Tomcat会话存储在Redis中: https://github.com/chexagon/redis-session-manager

在src / webapp / META-INF / context.xml文件中,我添加了新命令:

<Manager className="com.crimsonhexagon.rsm.redisson.SingleServerSessionManager"
             endpoint="redis://localhost:6379"
             sessionKeyPrefix="_ib_"
             saveOnChange="false"
             forceSaveAfterRequest="false"
             dirtyOnMutation="false"
             ignorePattern=".*\\.(ico|png|gif|jpg|jpeg|swf|css|js)$"
             maxSessionAttributeSize="-1"
             maxSessionSize="-1"
             allowOversizedSessions="false"
             connectionPoolSize="100"
             database="0"
             timeout="60000"
             pingTimeout="1000"
             retryAttempts="20"
             retryInterval="1000"
    />

如果jar文件位于Tomcat lib文件夹中,则一切正常。但是在生产中,如果我将jar添加到lib文件夹,则会导致错误。还有其他解决方法吗?我可以通过这样的方式更改context.xml以便在部署项目时可以找到经理className相关类吗? 附言有一些示例,但我无法理解: Adding external resources to class-path in Tomcat 8

如果有人能启发我,我将不胜感激。 预先感谢

1 个答案:

答案 0 :(得分:0)

我可以找到解决方法。 Maven中有一个用于部署War文件的插件。使用此插件可以将文件添加到war文件。例如,我创建了一个名为redis的文件夹,并将其添加到jar文件中。然后我添加了插件:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>redis</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
相关问题