I have a barebones project configured with maven and dropwizard. When I run the command java -jar target/dexcane-backend-1.0-SNAPSHOT.jar
I get the error "Error: Could not find or load main class com.dexcane.server.MyApplication". I get the same error if I try to specify the classpath using java -cp target/dexcane-backend-1.0-SNAPSHOT.jar com.dexcane.server.MyApplication
.
When I check the contents of the jar using jar tf
, I get
META-INF/
META-INF/MANIFEST.MF
com/
com/dexcane/
com/dexcane/server/
com/dexcane/server/configuration/
com/dexcane/server/resources/
META-INF/maven/
META-INF/maven/org.example/
META-INF/maven/org.example/dexcane-backend/
config.yml
com/dexcane/server/configuration/WebConfiguration.class
com/dexcane/server/resources/UsersResource.class
com/dexcane/server/resources/HelloWorldResource.class
com/dexcane/server/MyApplication.class
META-INF/maven/org.example/dexcane-backend/pom.xml
META-INF/maven/org.example/dexcane-backend/pom.properties
I'm not sure why the jar can't find the main class? FWIW, my main class extends the io.dropwizard.Application
class.
package com.dexcane.server;
import io.dropwizard.Application;
import io.dropwizard.setup.Environment;
import com.dexcane.server.configuration.WebConfiguration;
import com.dexcane.server.resources.HelloWorldResource;
public class MyApplication extends Application<WebConfiguration> {
public static void main(String[] args) throws Exception {
new MyApplication().run(args);
}
@Override
public void run(WebConfiguration webConfiguration, Environment environment) throws Exception {
final HelloWorldResource resource = new HelloWorldResource();
environment.jersey().register(resource);
}
}