Adam Bien's Weblog

polymer 2.0 with browsersync: a minimal installation / hot reloading

For a minimal polymer (2.0) with browsersync (hot reloading) installation perform the following steps:

  1. Install www.npmjs.com
  2. Install bower.io with: sudo npm install -g bower
  3. Install browsersync.io with: sudo npm install -g browser-sync

Create bower.json with minimal dependencies:


{
  "name": "(...)",
  "main": "(...).html",
  "dependencies": {
    "polymer": "Polymer/polymer#^2.0.0-rc.2"
  },
  "devDependencies": {
    "webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0-rc.5"
  },
  "resolutions": {
    "polymer": "^2.0.0-rc.2"
  }
}
    

Execute: bower install

Maintain your code in src folder

Launch browsersync with with: browser-sync start --server src -f "**/*" --serveStatic ./bower_components -b "google chrome" --no-notify

Browsersync will open chrome, serve static files (polymer libs) from bower_components folder and watch src folder. Any changes are going to be automatically pushed to the browser without reloading. Skip the bower_components folder in all imports:

	
<link rel="import" href="polymer/polymer-element.html">
(...)
<script src="webcomponentsjs/webcomponents-lite.js"></script>
	
    

Also see sample project: github.com/AdamBien/polymer-essential

Interested in lean apps? See you at Java EE Workshops at Munich Airport, Terminal 2 and particularly at Building HTML 5 Applications with WebStandards only


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Voxxed Days At Cern: Java EE -- As Cool As The LHC

After watching the keynote at Voxxed Day CERN I decided to add the "almost" to the title: "Java EE -- (Almost) As Cool As The LHC":

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Yes/NO User Input in Jenkinsfile

The method input within the Jenkinsfile suspends the build and waits infinitely for the user input with configurable options.

A Yes / No dialog waits for user input and returns true / false with the following code snippet:


def doesJavaRock = input(message: 'Do you like Java?', ok: 'Yes', 
                        parameters: [booleanParam(defaultValue: true, 
                        description: 'If you like Java, just push the button',name: 'Yes?')])

echo "Java rocks?:" + doesJavaRock

See you at Java EE Workshops at MUC Airport, particularly at the Java EE CI/CD, Testing and Quality workshop


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

JMS Redelivery, HA Singletons, Message Ordering, Test Coverage, JSON-P vs. JSON-B, UI Strategies or 36th airhacks.tv Episode Is Available

The 36th airhacks.tv, or 3 years anniversary live question and answers show with 96 live viewers and 20+ topics is available:

Past episodes are available at: airhacks.tv playlist.

Any questions left? Ask now https://gist.github.com/AdamBien/beae7dd8966a6d57b7225ba310b18abe and see you at April, 3rd, 6pm CET.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Java 8: An Endless Stream Of Random Numbers

The method Math#random is a Supplier<double> and can be used to generate an endless Stream or random numbers:


import java.util.stream.Stream;
import org.junit.Test;

public class RandomNumbersTest {

    @Test
    public void streamNumbers() {
        randomStream(10).
                limit(10).
                forEach(System.out::println);
    }


    public Stream<Long> randomStream(int range) {
        return Stream.generate(Math::random).
                map(n -> n * range).
                map(Math::round);
    }
}

The unit test above generates:

5 4 2 9 8 9 9 0 9 8

(...hopefully a different sequence on your machine :-))

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

HA Singletons, Clouds vs. On-Prem, Messaging and Message Ordering, UI-Stack Options, Swagger, Code Coverage or 36th airhacks.tv

Questions for the 36th airhacks.tv, March 6th, exceptionally 0.5h earlier, at 5.30pm. CET:

  1. Java EE 8 News
  2. HA Singletons and Java EE
  3. JMS-redelivery in the case of a rollback or system failure
  4. Decisions for hosting Java EE projects on premise or in the cloud
  5. Messaging systems and message ordering
  6. Where to put cross-cutting classes in the Boundary-Control-Entity structure?
  7. Deploying a single WAR into separated subfolders
  8. How to deal with "useful" libraries in Thin WAR environments?
  9. Test coverage of system tests.
  10. JSON-P vs JSON-B
  11. How to separate environments in Java EE?
  12. UI-stack options in modern Java EE applications
  13. How to manage database connections with TomEE and Docker?
  14. What is @javax.inject.Singleton?
  15. Swagger integration and Jersey or: how to document REST
  16. Field validation in JavaFX and FXML
  17. Do we have to override: getClasses/getSingletons of the javax.ws.rs.core.Application class?

Ask questions during the show via twitter mentioning me: http://twitter.com/AdamBien (@AdamBien) or using the hashtag: #airhacks. You can join the Q&A session live each first Monday of month, 6 P.M at airhacks.tv or http://www.ustream.tv/channel/adambien

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Pushing Full Profile Java EE Applications To Amazon EC2 Container Service

In this screencast I created from scratch with Maven, built (CentOS, JDK, Payara, Thin WAR, taken from docklands) and pushed a Full Profile Java EE 7 (Payara Full) application to Amazon EC2 Container Service cluster.

The ECS cluster is running on the smallest "free tier" available Amazon EC2 machine t2.micro (1 CPU and 1 GB RAM). t2.nano (512 MB max) would also work -- but is not eligible for free tier.

See you at Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

20+ Topics in 45 mins -- 35th airhacks.tv Questions and Answers

90 live attendees, 20+ topics in 45 mins ranging from Java EE 8 News over JPA relations in MSAs to cross-field validation. The 35th (2.2017) airhacks.tv is available:

Watch past episodes with: airhacks.tv playlist.

Any questions left? Ask now gist.github.com/AdamBien/4500d4f7e546ea7f242baaec2e2f6616 and see you at March, 6th, 6pm CET.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

JPA and Microservices, RxJava, CRUD and TX, Gradle, Cross Field Validation, Licensing, MDA or Topics For The 35th airhacks.tv

Questions (gist) for the 35th airhacks.tv, February 8th (exceptionally at Wednesday, not Monday), 6 pm CET:

  1. Java EE 8 News
  2. Java SDK for Oracle Bare Metal Cloud Services github.com/oracle/bmcs-java-sdk
  3. Handling JPA relationships in CRUD microservice scenarios
  4. The role of RxJava in typical enterprise applications
  5. JAX-RS: returning Response vs. objects and JSON vs. XML
  6. Useful Java EE 7 tools
  7. Cross-field entity validation
  8. GPL/LGPL, opensource and commercial projects
  9. What is www.pac4j.org?
  10. Transactions, CRUD-Services (BCE), EntityManager and connection sharing
  11. (SCM) Managing, Structuring and organizing microservices
  12. Gradle adoption, gradle vs. maven
  13. Dealing with (setup) scripts in Java EE environment
  14. Oracle JDK vs. openJDK and licensing
  15. Greatings from Panama: gitbook.com/book/avbravo/jmoordb
  16. The role of Model Driven Architecture in Java EE

Ask questions during the show via twitter mentioning me: http://twitter.com/AdamBien (@AdamBien) or using the hashtag: #airhacks. You can join the Q&A session live each first Monday of month, 6 P.M at airhacks.tv or http://www.ustream.tv/channel/adambien

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

JSON Is The New Data Transfer Object (DTO)

The JSON processing API comes with Java EE 7 and is already integrated with JAX-RS. JsonObject and JsonArray are serialized and deserialized by the JAX-RS runtime without any additional effort.

JsonObject is a Map<String, JsonValue> and so a generic and dynamic DTO.

Because the entities know their state and also have access to private data, the JSON-mapping happens directly within the domain objects:

    
public class Workshop {

    private String name;
    private int duration;

    public Workshop(String name, int duration) {
        this.name = name;
        this.duration = duration;
    }


    public Workshop(JsonObject input) {
        this.name = input.getString("name");
        this.duration = input.
                getJsonNumber("duration").
                intValue();
    }


    public JsonObject toJson() {
        return Json.createObjectBuilder().
                add("name", this.name).
                add("duration", this.duration).
                build();
    }
}
    
    

Now the JAX-RS resource class only has to invoke the entities method to map from and to the JsonObject representation:

        
@Stateless
@Path("workshops")
public class WorkshopsResource {

    @Inject
    RegistrationStore store;

    @GET
    public JsonArray all() {
        JsonArrayBuilder list = Json.createArrayBuilder();
        List<Workshop> all = this.store.all();
        all.stream().map(Workshop::toJson).forEach(list::add);
        return list.build();
    }

    @POST
    public void save(JsonObject input) {
        this.store.save(new Workshop(input));
    }
}
        
    
See you at Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License