Skip to content

Embedded Jetty and Gradle #1

@JazzyJes

Description

@JazzyJes

Hello,
First off, great example.

I am trying the fine approach into my preexisting project. I start the main() and encounter an issue when attempting to set the classpath resource to "webapp" (uncommented in code snippet below) which clearly is caused due to the webapp not existing inside the executing directory of that jetty launcher...

The difference with my project setup is that I use Gradle instead of Maven and that I therefore don't use maven-shade-plugin, but rather simply include the whole resources folder to my resulting .jar file.

When I start the EmbeddedJetty, then the new folder /bin folder is created under: com/acme/myproject and it has no trace of the webapp folder.

ServletContextHandler contextHandler = new ServletContextHandler();
    contextHandler.setErrorHandler(null);
    contextHandler.setContextPath(CONTEXT_PATH);
    contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
    contextHandler.addEventListener(new ContextLoaderListener(context));
    // PROBLEM: file:/home/jes/Development/git/foobar/bin/ is the working dir while i need to have it to ./../src/main/resource. How to?
    // FIX contextHandler.setResourceBase(new
    // ClassPathResource("webapp").getURI().toString());
    return contextHandler;

I can't seem to understand something crucial about my setup attempt :(
Is there a way to tweak the working directory of the EmbdeddeJetty main() method so that it isn't set to /bin? or is there a way join the whole thing?!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions