First off, this might be a dupe of Gradle build successful, error running jar
I've build a very basic Dropwizard project that is built with Gradle. My build.gradle
file looks something like this:
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'
}
When I run gradle build
, a ./build/libs/
folder is created that contains a jar called webservice-0.1.jar
. If I try to execute this jar with java -jar webservice-0.1.jar
, I get the error Error: Could not find or load main class com.mydomain.WebServiceApplication
.
Thing is, that file most certainly exists. I can do the following:
$ makedir tmp
$ cd tmp
$ unzip ../webservice-0.1.jar
$ ls ./com/mydomain/
and the file WebServiceApplication.class
is there. Is there some kind of classpath thing that I have to do in order to get java to find classes inside of my jar? I'm lost here.