Giter VIP home page Giter VIP logo

jersey-jump's Introduction

jersey-jump

A jump start module for creating webapp modules. build.gradle:

repositories {
    maven {
        name = 'sonatype-snapshots'
        url 'https://oss.sonatype.org/content/repositories/snapshots'
    }
}

dependencies {
    compile 'com.blacklocus:jersey-jump:1.0-SNAPSHOT'
}

To generate an all-in-one fat jar, add this to your module's build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
    }
}
apply plugin: 'fatjar'

fatJar {
    classifier = 'fat'
    manifest.attributes 'Main-Class': 'com.blacklocus.webapp.RunServer'
    exclude 'META-INF/*.SF'
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
}

You'll need to specify the base scan package as the default (scan all) won't work across jars. I don't know why this is, but it's pretty annoying.

For fatJar this would be a -D like -Dbase.pkg=your.company. For the gradle application plugin, do it through JAVA_OPTS:

export JAVA_OPTS="-Dbase.pkg=com.company"

web resources

Create classes that extend com.blacklocus.webapp.base.BaseJsonResource and annotate them in the usual Jersey ways. Note that RunServer initializes Jersey with a SingletonFactory, so all web resources and providers must be threadsafe. Example:

@Path("/stuff")
public class Stuff extends BaseJsonResource {

    private final MyService myService;

    // Jersey has a dead simple DI mechanic. To create injectable instances, annotate them with @Provider.
    public Stuff(@InjectParam MyService myService) {
        this.myService = myService;
    }

    @GET
    public String helloWorld() {
        return "hello world";
    }

    @GET
    public ResponsePojo example(@QueryParam("isContrived") Boolean isContrived) {
        ResponsePojo response = new ResponsePojo();
        response.success = isContrived;
        // Note that by extending BaseJsonResource, objects will be serialized to/from json using
        // com.blacklocus.webapp.app.DefaultObjectMapper
        return response;
    }
}

class ResponsePojo {
    public Boolean success;
}

static files

Place them in your project directory under src/main/webapp/static/. To mark them as source files in both IntelliJ and in the fat jar build, build.gradle:

sourceSets {
    main.resources.srcDir 'src/main/webapp'
}

The static/ directory will end up at the root of the fat jar.

Development

IntelliJ copies files to a temporary directory on build/run. If you would like to be able to edit static files while your webapp is running, this property will cause RunServer to configure Jetty to point directly at your source directories rather than the temporary build out generated by IntelliJ. Notice here, the static/ dir is not implied and must be explicitly included:

-Dbase.static_dirs=src/main/webapp/static/

This property does accept multiple locations, if such a layering during development is desired.

-Dbase.static_dirs=submodule-1/src/main/webapp/static/;submodule-0/src/main/webapp/static/

License

Copyright 2013 BlackLocus

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

jersey-jump's People

Contributors

dirkraft avatar rholder avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sirfnain

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.