gpt4 book ai didi

java - 为什么在通过 Intellij 使用 tomcat 启动 Web 应用程序时有时会出现奇怪的 FileNotFoundExceptions

转载 作者:行者123 更新时间:2023-11-28 23:12:19 24 4
gpt4 key购买 nike

我正在使用 SpringSpring Security 开发一个 Java 8 Web 应用程序。它是一个简单的 Web 应用程序,正在通过 aven 构建到 war-File 中。我的 IDE 是 Intellij IDEA Ultimate,该应用程序正在使用 Intellij 部署到 Tomcat 8.5。构建过程使用两个 Maven 配置文件

如果我尝试通过 Intellij Tomcat 运行配置启动应用程序,我有时(不是每次,这也很奇怪)在 target\webapp\WEB- INF\lib\。依赖项都在 pom 文件中定义,就像任何标准 Maven 项目一样,所以这里没什么特别的。任何地方都没有相对或绝对文件路径!如果我检查“丢失”的 jar 然后我找到它们,它们都在它们应该在的地方(“<%Project_Root%>\target\webapp\WEB-INF\lib\”)但是 Intellij 说它们不在

示例错误堆栈:

    17-May-2019 13:23:11.715 SCHWERWIEGEND [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.reload Exception starting Context with name [/collphir]
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/collphir]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3839)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:291)
at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5612)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1389)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1393)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1393)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1361)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: java.io.FileNotFoundException: C:\GITROOT\adesso\collphir4_backend\target\webapp\WEB-INF\lib\spring-data-jpa-1.11.1.RELEASE.jar (Das System kann die angegebene Datei nicht finden)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.isMultiRelease(AbstractSingleArchiveResourceSet.java:121)
at org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:250)
at org.apache.catalina.webresources.StandardRoot.getResourcesInternal(StandardRoot.java:327)
at org.apache.catalina.webresources.CachedResource.validateResources(CachedResource.java:140)
at org.apache.catalina.webresources.Cache.getResources(Cache.java:147)
at org.apache.catalina.webresources.StandardRoot.getResources(StandardRoot.java:315)
at org.apache.catalina.webresources.StandardRoot.getClassLoaderResources(StandardRoot.java:231)
at org.apache.catalina.util.ExtensionValidator.validateApplication(ExtensionValidator.java:146)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5062)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 8 more
Caused by: java.io.FileNotFoundException: C:\GITROOT\adesso\collphir4_backend\target\webapp\WEB-INF\lib\spring-data-jpa-1.11.1.RELEASE.jar (Das System kann die angegebene Datei nicht finden)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:196)
at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:181)
at org.apache.catalina.webresources.AbstractArchiveResourceSet.openJarFile(AbstractArchiveResourceSet.java:308)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.isMultiRelease(AbstractSingleArchiveResourceSet.java:116)
... 17 more

摘 self 的 pom.xml:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<packagingExcludes>
%regex[app-(?!${portal.frontend-base}).*],
%regex[profiles/(?!${portal.client-code}).*],
**/build/**,
**/scss/**,
**/node_modules/**,
**/*.map,
**/jsDoc.js
</packagingExcludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
<webappDirectory>target/webapp</webappDirectory>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<company>${project.organization.name}</company>
<application>${portal.backend-base}</application>
<build-date>${buildDateTime}</build-date>
<build-revision>${buildRevision}</build-revision>
<scm-branch>${scmBranch}</scm-branch>
</manifestEntries>
</archive>
<webResources>
<!-- copy/parse context.xml -->
<resource>
<directory>src/main/resources/META-INF/</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>context.xml</include>
</includes>
</resource>
<!-- copy/parse web.xml -->
<resource>
<directory>src/main/webapp/WEB-INF/</directory>
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>web.xml</include>
</includes>
</resource>
<!-- copy/parse index.html -->
<resource>
<directory>src/main/webapp/app-${portal.frontend-base}/</directory>
<filtering>true</filtering>
<includes>
<include>index*.html</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>

<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.4</version>
</dependency>

<!-- [...] -->
</dependencies>

最佳答案

在你的 pom.xml 中添加 jar 依赖 -

Dependencies : add dependency in your pom.xml

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.1.RELEASE</version>
</dependency>

Build Configuration :

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>

</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<!--<skipMain>true</skipMain> -->
<skip>true</skip>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

关于java - 为什么在通过 Intellij 使用 tomcat 启动 Web 应用程序时有时会出现奇怪的 FileNotFoundExceptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56185612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com