Coder Social home page Coder Social logo

js-generator-for-jax-rs's Introduction

a Maven plugin to generate JavaScript for JAX-RS

This Maven plugin helps you to generate JavaScript to commnicate with server. It parses your controllers, and generate JavaScript files to send Ajax request.

Here is an example. Generated JavaScript depends on jQuery and RequireJS.

define(['jquery', 'exports'], function($, exports) {
  'use strict';
  var baseURL = $('meta[name="app-data"]').data('context-path') + '/resources';
  exports.load = function (message) {
    return $.ajax({
        cache: false,
        url: baseURL + '/sample/',
        type: 'get',
        data: {'message':message}
    }).promise();
  };
});

How to use

modify your pom.xml

js-generator-for-jax-rs is implemented as a Maven plugin. You have to modify your pom.xml to use it. This plugin will parse classes in packageName, and output JavaScript files into outputDirectory.

    <build>
        <plugins>
            <plugin>
                <groupId>jp.co.worksap.jax_rs</groupId>
                <artifactId>js-generator-for-jax-rs</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <packageName>jp.co.worksap.sample</packageName>
                    <outputDirectory>target/js/jax-rs</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>

ignore generated code

Generated code should not be stored in version management system like git. So it is good to put them into target directory.

If you cannot, please modify .gitignore to ignore generated code.

kick Maven to generate JavaScript

In this case, process-sources goal will generate JavaScript into target/js/jax-rs. You can change goal by phase configuration.

add meta tag into HTML

To tell your context path, please add meta tag into your HTML. JavaScript will send Ajax request to ${context-path}/resources/${specified-path}.

<meta name="app-data" data-context-path="context-path">

History

0.1

  • First release

0.2

  • Added README.md for user
  • Supported Maven sub module
  • Avoided JSLint warning for +''

0.3

  • Supported using outer artifact as returned value

0.4

  • Added module name for each API.js

0.5

  • Switched to use data-attribute to decide context path instead of location.pathname

0.6

  • Removed module name from generated code

1.0.0

  • Published at GitHub

License

Copyright 2013 Works Applications. Co.,Ltd.

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.

js-generator-for-jax-rs's People

Contributors

kengotoda avatar worksap-bot avatar yang-ling avatar

Watchers

James Cloos avatar Yi Siqi avatar

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.