我在these instructions之后创建了可执行jar。
我在MacOS上使用STS程序。创建jar文件后,它在MacOS上工作正常,但在Windows上我得到以下错误:
INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
Apr 12, 2017 6:42:48 PM org.apache.catalina.startup.ContextConfig init
SEVERE: Exception fixing docBase for context []
java.io.FileNotFoundException: C:\Users\John\.extract\webapps\ROOT.war (The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.<init>(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.getJarFile(Unknown Source)
at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:113)
at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:720)
at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:843)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:387)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:401)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Apr 12, 2017 6:42:48 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Invalid or unreadable WAR file : C:\Users\John\.extract\webapps\ROOT.war
at org.apache.naming.resources.WARDirContext.setDocBase(WARDirContext.java:136)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4906)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5086)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Apr 12, 2017 6:42:48 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Apr 12, 2017 6:42:48 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Apr 12, 2017 6:42:48 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
Apr 12, 2017 6:42:48 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
我的pom.xml包含以下创建jar的部分:
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<server>192.168.1.85</server>
<path>/</path>
<enableNaming>false</enableNaming>
<finalName>guard_server.jar</finalName>
<charset>utf-8</charset>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
有没有解决方案?
UPD:在Windows上编译项目后问题仍然存在,因此不存在平台问题。