我在Eclipse中进行了以下项目设置:
project
build.gradle
libraries.gradle
settings.gradle
ear-project
build.gradle
ejb-project
build.gradle
war-project
build.gradle
这是来自root项目的build.gradle:
apply from: "./libraries.gradle"
allprojects {
repositories {
mavenCentral()
}
}
buildscript {
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "findbugs"
group = "foo.bar"
version = "1.0.0-SNAPSHOT"
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
configurations {
provided {
description = "Non-exported compile-time dependencies"
}
}
sourceSets.main {
compileClasspath += configurations.provided
}
eclipse {
classpath {
plusConfigurations += configurations.provided
}
}
dependencies {
provided(libraries.javaee)
provided(libraries.ejb)
provided(libraries.cdi)
provided(libraries.jpa)
}
}
ear-project build.gradle:
apply plugin: "ear"
dependencies {
deploy project(path: ":ejb")
deploy project(path: ":war", configuration: "archives")
}
ejb-project build.gradle
apply plugin: "java"
war-project build.gradle
apply plugin: "war"
从命令行运行“gradle build”后,会生成.ear文件,但.war文件只包含未编译的.java类。 ejb项目中的类被编译为.class。为什么war-project中的类没有编译?
答案 0 :(得分:4)
Java文件必须位于src/main/java
。不是src/main/webapp
。 src/main/webapp
是webapp静态资产所在的目录:JSP文件,HTML文件,JS文件等。