首先,这可能是Gradle build successful, error running jar
的欺骗我构建了一个使用Gradle构建的非常基本的Dropwizard项目。我的build.gradle
文件看起来像这样:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
// use Java 1.8 by default
sourceCompatibility = 1.8
targetCompatibility = 1.8
// default to UTF-8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
// application version and name
mainClassName='com.mydomain.WebServiceApplication'
version = '0.1-' + (System.getenv("SVN_REVISION") == null ? "0" : System.getenv("SVN_REVISION"))
jar {
manifest {
attributes 'Implementation-Title': 'WebService',
'Implementation-Version': version,
'Main-Class': mainClassName
}
}
// project variables go here
project.ext {
dropwizardVersion='0.9.1'
}
// repositories that we're getting libraries from
repositories {
mavenCentral()
}
dependencies {
// compile-time dependencies
compile (
'commons-collections:commons-collections:3.2',
'io.dropwizard:dropwizard-core:' + dropwizardVersion,
'io.dropwizard:dropwizard-client:' + dropwizardVersion,
'org.logback-extensions:logback-ext-loggly:0.1.4',
'ch.qos.logback.contrib:logback-json-classic:0.1.2',
'ch.qos.logback.contrib:logback-jackson:0.1.2'
)
// test dependencies - these will be stripped from production jar
testCompile (
'io.dropwizard:dropwizard-testing:' + dropwizardVersion,
'junit:junit:4.+'
)
}
run {
args 'server', './src/main/resources/config.yml'
}
当我运行gradle build
时,会创建一个包含名为./build/libs/
的jar的webservice-0.1.jar
文件夹。如果我尝试使用java -jar webservice-0.1.jar
执行此jar,则会收到错误Error: Could not find or load main class com.mydomain.WebServiceApplication
。
事情是,那个文件肯定存在。我可以做到以下几点:
$ makedir tmp
$ cd tmp
$ unzip ../webservice-0.1.jar
$ ls ./com/mydomain/
,文件WebServiceApplication.class
就在那里。为了让java在我的jar里面找到类,我是否需要做某种类路径事务?我迷失了。