apply plugin: 'java'
apply plugin: 'application'
project.ext {
title = 'DWSample'
baseName = 'DWSample'
mainClass = 'com.hjess.dwsample.MainApp'
version = '1.0.0'
}
task copyData(type:Copy) {
from 'src/main/conf'
into 'build/libs'
}
task release(type: Jar, dependsOn: 'copyData') {
manifest {
attributes 'Implementation-Title': project.ext.title,
'Implementation-Version': project.ext.version,
'Main-Class': project.ext.mainClass
}
baseName = project.ext.baseName + project.ext.version
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jar
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'io.dropwizard', name: 'dropwizard-core', version: '1.1.4'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
server:
applicationConnectors:
- type: http
port: 8080
E:\DWSample\server\build\libs>java -jar DWSample1.0.0.jar server main.yaml
main.yaml has an error:
* Failed to parse configuration at: server.applicationConnectors.[0]; Could not resolve type id 'http' into a subtype of [simple type, class io.dropwizard.jetty.ConnectorFactory]: known type ids = [ConnectorFactory]
at [Source: N/A; line: -1, column: -1] (through reference chain: com.hjess.dwsample.MainConf["server"]->io.dropwizard.server.DefaultServerFactory["applicationConnectors"]->java.util.ArrayList[0])
Your YAML file is hard to read. Is really everything written on one line? Could you please edit your question so that code/configuration is displayed as it is in your files?
@WeJoy You have to properly create an Uber-JAR and merge service files.
Also see http://www.dropwizard.io/1.1.4/docs/getting-started.html#building-fat-jars
There's the Gradle Shadow plugin which can be used for this.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
project.ext {
baseName = 'DWSample'
mainClass = 'com.hjess.dwsample.MainApp'
version = '1.0.0'
classifier = 'release'
}
shadowJar {
mergeServiceFiles()
mainClassName = project.ext.mainClass
baseName = project.ext.baseName
classifier = project.ext.classifier
version = project.ext.version
}
task release(type: Copy, dependsOn: 'shadowJar') {
from 'src/main/conf'
into 'build/libs'
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
def dwVersion = '1.1.4'
compile group: 'io.dropwizard', name: 'dropwizard-core', version: dwVersion
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
I'm using dropwizard 0.9.2 and facing this issue. I've been successfully running my application without using any shadow plugin. But suddenly it stopped working and I face the same issue while trying the run the jar file.
Running jar : java -jar ProjectName-1.0-SNAPSHOT.jar server configuration.yml
Here's my gradle file
group 'myGroup'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
maven { url 'http://myArtifactory/jcenter' }
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'io.dropwizard:dropwizard-core:0.9.2'
compile "org.glassfish.jersey.core:jersey-client:2.21"
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.22.2'
compile group: 'org.json', name: 'json', version: '20090211'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '2.10.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'ProjectName',
'Implementation-Version': version,
'Main-Class': 'mypackage.DropWizardApplication'
}
baseName = project.name
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
0.9.2 is good without shadowJar, any version above is not.
Any ideas appreciated
Using 1.3.5 shadowjar/gradle and I'm getting (getting the same thing when I use gradle jar alone)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.fasterxml.jackson.module.afterburner.util.MyClassLoader (file:/Users/xxxx/git/myfitnesspal/build/libs/myfitnesspal-1.0-SNAPSHOT-all.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.fasterxml.jackson.module.afterburner.util.MyClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
io.dropwizard.configuration.ConfigurationParsingException: out/production/resources/mypal.yaml has an error:
with config snippet:
server:
applicationConnectors:
- type: http
port: 8080
Most helpful comment
Well, the problem has been solved by using https://github.com/johnrengelman/shadow, Thanks for the help!
Codes here