我有一个 Gradle 项目,我正在尝试使用 Jetty 运行它。
我的 build.gradle
文件如下所示。
build.gradle
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'
[jettyRun, jettyRunWar]*.httpPort = 8080
[jettyRun, jettyRunWar]*.contextPath = ''
[jettyRun, jettyRunWar]*.daemon = true
[jettyRun, jettyRunWar, jettyStop]*.stopPort = 8081
[jettyRun, jettyRunWar, jettyStop]*.stopKey = 'stop'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
test {
java {
srcDirs = ['src/test/java']
}
}
}
dependencies {
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.14'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.14'
compile 'com.google.guava:guava:14.0.1'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.mockito:mockito-all:1.10.19'
testCompile 'org.eclipse.jetty:jetty-server:9.4.7.v20170914'
testCompile 'org.eclipse.jetty:jetty-webapp:9.4.7.v20170914'
}
我正在尝试从命令行运行这个项目,我使用的命令是:
./gradlew
应该构建项目,并输出以下内容:Jetty 插件已被弃用,并计划在 Gradle 4.0 中删除。考虑改用 Gretty ( https://github.com/akhikhl/gretty) 插件。 在 build_6xw4u3prr68h02k136x2vqowd.run(/myproject/build.gradle:3) :帮助
欢迎使用 Gradle 3.2.1。
gradle jettyRun
失败并显示 Plugin with id 'jetty' not found。
那么问题来了,我该如何运行这样一个项目?请注意,我没有编写这个项目,我只需要在我的本地机器上运行它。
最佳答案
我不是 Gradle 的专家,只是一个初学者,但我想我找到了一些可以帮助你的东西。 我还阅读了有关将 jetty 与 gradle 结合使用的信息,因为我经常将它与 Maven 一起使用。
事实证明,不再支持 Jetty 作为插件,您可以在此处找到:https://docs.gradle.org/current/userguide/jetty_plugin.html
相反,您应该使用 gretty 来达到相同的目的: https://plugins.gradle.org/plugin/org.gretty
希望这对您有所帮助。
关于java - 如何使用 Gradle 运行 Jetty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51979257/