我正在构建一个用Java构建的个人项目(项目名称:no-hold)的REST API。 我正在使用Spring Boot和Jetty这样做,并将其作为WAR部署到Google App Engine上。
但是,当我尝试运行mvn jetty:run-exploded
时,出现以下错误:
[INFO] --- jetty-maven-plugin:9.4.3.v20170317:run-exploded (default-cli) @ no-hold ---
[INFO] Configuring Jetty for project: no-hold
[INFO] Logging initialized @3732ms to org.eclipse.jetty.util.log.Slf4jLog
[INFO] Context path = /
[INFO] Tmp directory = /Users/lucasjohnston/code/no-hold/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] jetty-9.4.3.v20170317
[INFO] Scanning elapsed time=575ms
[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@3c0bbc9f{/,file:///Users/lucasjohnston/code/no-hold/target/no-hold-1.0-SNAPSHOT/,UNAVAILABLE}{/Users/lucasjohnston/code/no-hold/target/no-hold-1.0-SNAPSHOT}
org.eclipse.jetty.util.MultiException: Multiple exceptions
at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations (AnnotationConfiguration.java:452)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure (AnnotationConfiguration.java:365)
at org.eclipse.jetty.webapp.WebAppContext.configure (WebAppContext.java:512)
at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1437)
at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:799)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:261)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:540)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart (JettyWebAppContext.java:432)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:113)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart (ContextHandlerCollection.java:161)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:113)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start (Server.java:452)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart (Server.java:419)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty (AbstractJettyMojo.java:460)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute (AbstractJettyMojo.java:328)
at org.eclipse.jetty.maven.plugin.JettyRunWarExplodedMojo.execute (JettyRunWarExplodedMojo.java:69)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.eclipse.jetty.util.MultiException: Multiple exceptions
at org.eclipse.jetty.annotations.AnnotationParser.parseJar (AnnotationParser.java:878)
at org.eclipse.jetty.annotations.AnnotationParser.parse (AnnotationParser.java:837)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call (AnnotationConfiguration.java:159)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run (AnnotationConfiguration.java:464)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:672)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:590)
at java.lang.Thread.run (Thread.java:745)
Caused by: java.lang.RuntimeException: Error scanning entry META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class from jar file:///Users/lucasjohnston/code/no-hold/target/no-hold-1.0-SNAPSHOT/WEB-INF/lib/log4j-api-2.10.0.jar
at org.eclipse.jetty.annotations.AnnotationParser.parseJar (AnnotationParser.java:891)
at org.eclipse.jetty.annotations.AnnotationParser.parse (AnnotationParser.java:837)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call (AnnotationConfiguration.java:159)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run (AnnotationConfiguration.java:464)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:672)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:590)
at java.lang.Thread.run (Thread.java:745)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init> (Unknown Source)
at org.objectweb.asm.ClassReader.<init> (Unknown Source)
at org.objectweb.asm.ClassReader.<init> (Unknown Source)
at org.eclipse.jetty.annotations.AnnotationParser.scanClass (AnnotationParser.java:959)
at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry (AnnotationParser.java:940)
at org.eclipse.jetty.annotations.AnnotationParser.parseJar (AnnotationParser.java:887)
at org.eclipse.jetty.annotations.AnnotationParser.parse (AnnotationParser.java:837)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call (AnnotationConfiguration.java:159)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run (AnnotationConfiguration.java:464)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:672)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:590)
at java.lang.Thread.run (Thread.java:745)
当部署到GAE时,会抛出403 Forbidden。
这是我目前的设置:
的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<groupId>com.bytelucas.flex.nohold</groupId>
<artifactId>no-hold</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<appengine.maven.plugin>1.3.2</appengine.maven.plugin>
<jetty.maven.plugin>9.4.3.v20170317</jetty.maven.plugin>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.maven.plugin}</version>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin}</version>
<configuration>
<!-- deploy configuration -->
<!--
<deploy.promote>true</deploy.promote> <!~~ DEFAULT value ~~>
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion> <!~~ DEFAULT value ~~>
-->
</configuration>
</plugin>
</plugins>
</build>
</project>
的build.gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+'
classpath 'org.akhikhl.gretty:gretty:+'
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE"
}
}
repositories {
maven {
url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central
}
jcenter()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: "org.springframework.boot"
dependencies {
providedCompile 'com.google.appengine:appengine:+'
compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-tomcat'
}
compile 'org.eclipse.jetty:jetty-webapp:9.+'
compile 'org.eclipse.jetty:jetty-jsp:9.+'
compile group: 'org.akhikhl.gretty', name: 'gretty-spring-boot-plugin-commons', version: '0.0.24'
compile group: "com.twilio.sdk", name: "twilio", version: "7.17.+"
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'jetty9'
springBoot = true
springBootVersion = '2.0.1.RELEASE'
}
appengine {
deploy {
stopPreviousVersion = true
promote = true
}
}
group = 'com.bytelucas.appengine'
version = '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
Api.java:
package com.bytelucas.appengine.nohold;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackageClasses = ApiController.class)
public class Api extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Api.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Api.class);
}
}
ApiController.java
package com.bytelucas.appengine.nohold;
import javax.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ApiController {
@GetMapping("/api")
public Name apiGetRequest(
@NotNull @RequestParam(value="name") String name) {
return new Name(name);
}
}
此时我碰到了一堵砖墙,所以任何帮助都会非常感激!
答案 0 :(得分:0)
您正在使用Java 9 JEP-238(MultiRelease Jar Files)支持的依赖项。
META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class from jar file:///Users/lucasjohnston/code/no-hold/target/no-hold-1.0-SNAPSHOT/WEB-INF/lib/log4j-api-2.10.0.jar
http://openjdk.java.net/jeps/238
首先在Jetty 9.4.7.v20170914中引入了对Jetty中JEP-238的支持。
从那时起,Jetty中的JEP-238支持已有很多更新。
JEP-238支持错误修复的最新版本是Jetty 9.4.9.v20180320