SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
Extending 
Build 
to 
the 
Client: 
A 
Maven 
User's 
Guide 
to 
Grunt.js 
Petr 
Jiricka 
Software 
Development 
Manager 
NetBeans 
IDE 
team, 
Oracle 
September 
29, 
2014 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved.
Safe 
Harbor 
Statement 
The 
following 
is 
intended 
to 
outline 
our 
general 
product 
direction. 
It 
is 
intended 
for 
information 
purposes 
only, 
and 
may 
not 
be 
incorporated 
into 
any 
contract. 
It 
is 
not 
a 
commitment 
to 
deliver 
any 
material, 
code, 
or 
functionality, 
and 
should 
not 
be 
relied 
upon 
in 
making 
purchasing 
decisions. 
The 
development, 
release, 
and 
timing 
of 
any 
features 
or 
functionality 
described 
for 
Oracle’s 
products 
remains 
at 
the 
sole 
discretion 
of 
Oracle. 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
2
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Program 
Agenda 
Evolution 
of 
Java 
Web 
Applications 
Introducing 
Grunt.js 
Moving 
from 
Maven 
to 
Maven 
+ 
Grunt.js 
Compilation, 
Minification, 
Unit 
testing, 
… 
Development 
Cycle 
with 
Grunt.js 
and 
NetBeans 
IDE 
1 
2 
3 
4 
5 
3
Evolution 
of 
Java 
Web 
Applications 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
4
Traditional 
Java 
Web 
Application 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Server-­‐side 
– Server-­‐side 
business 
logic 
and 
data 
access 
code 
– Presentation 
logic 
and 
view 
controllers, 
template 
processing 
• Client-­‐side 
– Views 
using 
a 
template-­‐based 
framework 
(JSF, 
Wicket, 
Spring 
MVC, 
…) 
• Packaged 
together 
into 
a 
.war 
file, 
typically 
using 
Maven 
5
Modern 
Java 
Web 
Application 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Server-­‐side 
– Server-­‐side 
business 
logic 
and 
data 
access 
code 
– Exposed 
as 
RESTful 
services 
(typically 
JSON) 
— 
“thin 
server” 
• Client-­‐side 
– MVVM 
JavaScript 
framework 
(Model-­‐View-­‐Viewmodel): 
AngularJS, 
Ember, 
Backbone, 
Knockout, 
… 
– Client-­‐side 
navigation 
logic, 
“single-­‐page 
application” 
– Consumes 
JSON 
data 
from 
the 
server 
• Typically 
still 
packaged 
together 
into 
a 
.war 
file 
using 
Maven 
6
Client-­‐side 
build 
tasks 
using 
Maven? 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• How 
do 
we 
do: 
– Client-­‐side 
library 
management 
analogous 
to 
Maven 
repositories? 
– Compilation 
of 
preprocessor 
languages 
like 
SASS, 
LESS 
– Compilation 
of 
languages 
like 
CoffeeScript, 
TypeScript? 
– Optimization 
of 
static 
files 
(concatenation, 
minification, 
compression, 
image 
sprites)? 
– Versioning 
of 
static 
resources 
to 
enable 
long-­‐term 
caching 
by 
browsers? 
– Unit 
testing 
and 
integration 
testing 
of 
JavaScript 
files? 
• And 
what 
is 
the 
overall 
development 
cycle? 
7
Introducing 
Grunt.js 
and 
Related 
Tools 
gruntjs.com 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
8
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
First, 
let’s 
talk 
about 
Node.js 
• JavaScript 
runtime 
for 
server 
applications, 
but 
also 
for 
command-­‐line 
apps 
• Includes 
node 
package 
manager 
(npm), 
online 
repository 
of 
packages 
• Packages 
installed 
globally 
or 
per-­‐project 
– Per-­‐project 
packages 
specified 
in 
package.json 
file 
• Platform-­‐specific 
installers 
available 
at 
nodejs.org 
– Installer 
adds 
node 
and 
npm 
commands 
on 
your 
system 
PATH 
• Tip: 
Use 
Node 
Version 
Manager 
(nvm) 
to 
manage 
Node.js 
distribution(s) 
– See 
https://github.com/creationix/nvm 
9
Next, 
we 
need 
to 
introduce 
Bower 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Package 
manager 
for 
the 
client-­‐side 
– Manages 
frameworks, 
libraries, 
assets, 
… 
– Supports 
various 
sources: 
git 
or 
svn 
repositories, 
download 
from 
URLs, 
archives, 
… 
– Controlled 
by 
bower.json 
(and 
.bowerrc) 
files 
• Install 
using 
npm, 
then 
use 
bower 
command: 
– npm install -g bower 
: 
installs 
bower 
as 
a 
global 
Node.js 
module! 
– bower install --save jquery 
: 
installs 
jQuery 
(latest 
version) 
to 
this 
project 
and 
adds 
an 
entry 
to 
bower.json 
– bower install 
: 
installs 
everything 
specified 
in 
bower.json 
10
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
And 
finally, 
Grunt.js 
• JavaScript 
task 
runner 
— 
or 
simply 
a 
build 
tool 
• Install 
using 
npm: 
– npm install --save-dev grunt 
: 
installs 
Grunt 
in 
this 
project 
and 
saves 
it 
to 
the 
project’s 
package.json! 
– npm install -g grunt-cli 
: 
installs 
the 
Grunt 
command 
as 
a 
global 
Node.js 
module 
(and 
adds 
it 
to 
your 
PATH)! 
• Gruntfile.js 
defines 
and 
configures 
tasks 
11
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Grunt 
plugins 
and 
tasks 
• Plugins 
provide 
predefined 
functionality 
and 
make 
it 
available 
as 
tasks 
• Installing 
a 
plugin: 
– npm install --save-dev grunt-usemin 
: 
installs/saves 
grunt-­‐usemin 
plugin 
(which 
provides 
useminPrepare 
and 
usemin 
tasks) 
in 
this 
project 
12
Configuring 
tasks 
and 
loading 
plugins 
in 
Gruntfile.js 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
grunt.initConfig({! 
usemin : {! 
options: {! 
dirs: ['dist']! 
},! 
html: ['dist/{,*/}*.html']! 
} ! 
});! 
! 
// Load the plugin that provides the "usemin" task.! 
grunt.loadNpmTasks('grunt-usemin'); 
13
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Custom 
tasks, 
default 
task 
grunt.registerTask('clean-build',! 
'Main clean/build task with SASS preprocessing.',! 
['clean:all', 'build', 'sass']);! 
! 
// Task to run when running ‘grunt’ without parameters! 
grunt.registerTask('default', ['clean-build']);! 
14
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Grunt 
Tips 
// Time how long tasks take. Can help optimize build times.! 
require('time-grunt')(grunt);! 
! 
// Load grunt tasks automatically! 
require('load-grunt-tasks')(grunt);! 
• You 
also 
need 
this 
in 
package.json: 
! 
"devDependencies": {! 
"time-grunt": "^0.4.0",! 
"load-grunt-tasks": "^0.4.0",! 
} 
15
Moving 
from 
Maven 
to 
Maven 
+ 
Grunt.js 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
16
Changing 
the 
project’s 
source 
structure 
After 
(Maven 
+ 
Grunt.js) 
project! 
!"# client! 
$ !"" bower_components! 
$ !"" node_modules! 
$ !"" public_html! 
$ !"" dist! 
$ !"" bower.json! 
$ !"" Gruntfile.js! 
$ %"" package.json! 
%"# server! 
!"" src! 
!"" target! 
%"" pom.xml! 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
17 
Before 
(Maven) 
project! 
!"" src! 
!"" target! 
%"" pom.xml! 
! 
• Sources 
moved 
from 
src/main/webapp 
to 
client/public_html! 
• Need CORS (cross-origin 
resource sharing) filter 
for development-time
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Bower 
libraries 
downloaded 
to 
a 
separate 
staging 
area 
• Bower 
libraries 
copied 
to 
source 
tree 
– NetBeans 
recommended 
approach 
• SASS 
compilation 
• Unit 
testing 
18 
• Concatenation 
• Minification 
• Static 
resource 
revisions 
From 
Source 
to 
Production 
Development 
Environment 
Production 
Distribution 
Source
Manage 
libraries 
using 
Bower 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Declare 
libraries 
in 
bower.json, 
instead 
of 
placing 
them 
directly 
under 
the 
web 
root 
• Copy 
them 
under 
e.g. 
public_html/libs/vendor 
using 
the 
bowercopy 
grunt 
task 
(from 
the 
grunt-­‐bowercopy 
node 
plugin) 
• Many 
Bower 
components 
contain 
“junk” 
other 
than 
the 
binary 
itself, 
so 
need 
to 
be 
careful 
what 
to 
copy 
19
Bundle 
client 
and 
server 
into 
a 
.war 
file 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Top-­‐level 
maven 
project 
called 
bundle 
(next 
to 
client 
and 
server) 
• pom.xml 
uses 
war 
packaging 
type 
• uses 
grunt-maven-plugin 
to 
call 
Grunt 
before 
packaging 
the 
result 
– https://github.com/allegro/grunt-­‐maven-­‐plugin 
20
Compilation, 
Minification, 
Unit 
testing, 
… 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
21
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Compile 
SASS 
to 
CSS 
• Uses 
sass 
task 
(from 
the 
grunt-contrib-sass 
node 
plugin) 
! 
sass: {! 
dist: {! 
files: {! 
'main.css': 'main.scss',! 
'widgets.css': 'widgets.scss'! 
}! 
}! 
} 
22
Minify 
and 
concatenate 
JavaScript 
and 
CSS 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Several 
tasks 
orchestrated 
by 
the 
grunt-usemin 
node 
plugin 
– useminPrepare 
prepares 
the 
configuration 
– concat 
concatenates 
files 
(usually 
JS 
or 
CSS). 
– uglify 
minifies 
JS 
files. 
– cssmin 
minifies 
CSS 
files. 
– filerev 
revisions 
static 
assets 
through 
a 
file 
content 
hash. 
– usemin 
replaces 
references 
in 
HTML 
files 
• Output 
should 
be 
written 
to 
a 
separate 
dist 
directory 
• copy 
task 
should 
copy 
all 
the 
other 
files 
from 
public_html 
to 
dist 
23
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Unit 
testing 
using 
Karma 
• place 
test 
sources 
under 
client/test 
(sibling 
of 
public_html) 
• karma.conf.js 
file 
controls 
the 
configuration 
of 
Karma 
• grunt-karma 
plugin 
provides 
karma 
task 
with 
several 
subtasks 
– grunt.registerTask('test', ['karma:run']); // PhantomJS! 
– grunt.registerTask('test-chrome', ['karma:run-chrome']);! 
– grunt.registerTask('test-coverage', ['karma:coverage']);! 
– grunt.registerTask('test-debug', ['karma:debug']); 
24
Development 
Cycle 
with 
Grunt.js 
and 
NetBeans 
IDE 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
25
Development 
workflow 
from 
the 
command 
line 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• watch 
task 
(grunt-contrib-watch 
plugin) 
watches 
for 
changes 
in 
compiled 
files 
and 
recompiles 
them 
• Serve 
files 
using 
a 
lightweight 
web 
server 
• Reload 
files 
in 
the 
browser 
26
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
NetBeans 
IDE 
• Great 
editor 
for 
JavaScript, 
HTML, 
CSS, 
SASS, 
LESS, 
… 
– Supports 
frameworks 
and 
libraries 
like 
require.js, 
AngularJS, 
Knockout, 
… 
• Running, 
debugging 
and 
Visual 
CSS 
editing 
not 
only 
on 
Chrome 
— 
also 
on 
iOS 
and 
Android 
devices 
and 
simulators 
– Including 
support 
for 
packaging 
applications 
using 
the 
Cordova 
framework 
• Built-­‐in 
lightweight 
web 
server, 
recompile 
and 
refresh 
browser 
on 
save 
• Built-­‐in 
test 
runner 
• … 
and 
many 
more 
features 
27
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Resources 
• Grunt.js: 
gruntjs.com 
• Node.js: 
nodejs.org 
• Bower: 
bower.io 
• Karma: 
karma-­‐runner.github.io 
• SASS: 
sass-­‐lang.com 
• NetBeans 
IDE: 
netbeans.org 
• Project 
sources: 
https://github.com/pjiricka/affablebean-­‐maven-­‐grunt 
• Slides: 
http://www.slideshare.net/PetrJiricka 
28
Extending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.js

Weitere ähnliche Inhalte

Was ist angesagt?

Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
schoefmax
 

Was ist angesagt? (20)

How Flipkart scales PHP
How Flipkart scales PHPHow Flipkart scales PHP
How Flipkart scales PHP
 
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructuresMaster Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
 
cephfs with openstack manila based on bluestore and erasure code
cephfs with openstack manila based on bluestore and erasure codecephfs with openstack manila based on bluestore and erasure code
cephfs with openstack manila based on bluestore and erasure code
 
Lamp Introduction 20100419
Lamp Introduction 20100419Lamp Introduction 20100419
Lamp Introduction 20100419
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on Netscaler
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
 
Changes in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must KnowChanges in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must Know
 
OSGi for real in the enterprise: Apache Karaf - NLJUG J-FALL 2010
OSGi for real in the enterprise: Apache Karaf - NLJUG J-FALL 2010OSGi for real in the enterprise: Apache Karaf - NLJUG J-FALL 2010
OSGi for real in the enterprise: Apache Karaf - NLJUG J-FALL 2010
 
AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content Services
 
A Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container PlatformsA Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container Platforms
 
Magento 2 Workflows
Magento 2 WorkflowsMagento 2 Workflows
Magento 2 Workflows
 
ApacheCon EU 2014: Enterprise Development with Apache Karaf
ApacheCon EU 2014: Enterprise Development with Apache KarafApacheCon EU 2014: Enterprise Development with Apache Karaf
ApacheCon EU 2014: Enterprise Development with Apache Karaf
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
 
WebSphere Application Server Liberty Profile and Docker
WebSphere Application Server Liberty Profile and DockerWebSphere Application Server Liberty Profile and Docker
WebSphere Application Server Liberty Profile and Docker
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStack
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
 
Ruby on microsoft azure april 2014
Ruby on microsoft azure   april 2014Ruby on microsoft azure   april 2014
Ruby on microsoft azure april 2014
 

Andere mochten auch

Front end task automation using grunt, yeoman and npm(1)
Front end task automation using grunt, yeoman and npm(1)Front end task automation using grunt, yeoman and npm(1)
Front end task automation using grunt, yeoman and npm(1)
Frank Marcelo
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
Robert Nyman
 

Andere mochten auch (7)

Front end task automation using grunt, yeoman and npm(1)
Front end task automation using grunt, yeoman and npm(1)Front end task automation using grunt, yeoman and npm(1)
Front end task automation using grunt, yeoman and npm(1)
 
A new sdm classifier using jaccard mining procedure case study rheumatic feve...
A new sdm classifier using jaccard mining procedure case study rheumatic feve...A new sdm classifier using jaccard mining procedure case study rheumatic feve...
A new sdm classifier using jaccard mining procedure case study rheumatic feve...
 
Making maven and grunt play nice
Making maven and grunt play niceMaking maven and grunt play nice
Making maven and grunt play nice
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
 
Jaap : node, npm & grunt
Jaap : node, npm & gruntJaap : node, npm & grunt
Jaap : node, npm & grunt
 
Build Tools & Maven
Build Tools & MavenBuild Tools & Maven
Build Tools & Maven
 
Content strategy for the content experience wave
Content strategy for the content experience waveContent strategy for the content experience wave
Content strategy for the content experience wave
 

Ähnlich wie Extending Build to the Client: A Maven User's Guide to Grunt.js

Ähnlich wie Extending Build to the Client: A Maven User's Guide to Grunt.js (20)

Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
Core os dna_automacon
Core os dna_automaconCore os dna_automacon
Core os dna_automacon
 
Short-Training asp.net vNext
Short-Training asp.net vNextShort-Training asp.net vNext
Short-Training asp.net vNext
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java AppsWebinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
 
Node.js und die Oracle-Datenbank
Node.js und die Oracle-DatenbankNode.js und die Oracle-Datenbank
Node.js und die Oracle-Datenbank
 
Core os dna_oscon
Core os dna_osconCore os dna_oscon
Core os dna_oscon
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containers
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
Tutorial 1: Your First Science App - Araport Developer Workshop
Tutorial 1: Your First Science App - Araport Developer WorkshopTutorial 1: Your First Science App - Araport Developer Workshop
Tutorial 1: Your First Science App - Araport Developer Workshop
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and docker
 
Part 4: Custom Buildpacks and Data Services (Pivotal Cloud Platform Roadshow)
Part 4: Custom Buildpacks and Data Services (Pivotal Cloud Platform Roadshow)Part 4: Custom Buildpacks and Data Services (Pivotal Cloud Platform Roadshow)
Part 4: Custom Buildpacks and Data Services (Pivotal Cloud Platform Roadshow)
 
Best Practices for Running Kafka on Docker Containers
Best Practices for Running Kafka on Docker ContainersBest Practices for Running Kafka on Docker Containers
Best Practices for Running Kafka on Docker Containers
 
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudPHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the Cloud
 
Java EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The CloudJava EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The Cloud
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Java Builds with Maven and Ant
Java Builds with Maven and AntJava Builds with Maven and Ant
Java Builds with Maven and Ant
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platform
 
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Extending Build to the Client: A Maven User's Guide to Grunt.js

  • 1. Extending Build to the Client: A Maven User's Guide to Grunt.js Petr Jiricka Software Development Manager NetBeans IDE team, Oracle September 29, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
  • 2. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 2
  • 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Program Agenda Evolution of Java Web Applications Introducing Grunt.js Moving from Maven to Maven + Grunt.js Compilation, Minification, Unit testing, … Development Cycle with Grunt.js and NetBeans IDE 1 2 3 4 5 3
  • 4. Evolution of Java Web Applications Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 4
  • 5. Traditional Java Web Application Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Server-­‐side – Server-­‐side business logic and data access code – Presentation logic and view controllers, template processing • Client-­‐side – Views using a template-­‐based framework (JSF, Wicket, Spring MVC, …) • Packaged together into a .war file, typically using Maven 5
  • 6. Modern Java Web Application Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Server-­‐side – Server-­‐side business logic and data access code – Exposed as RESTful services (typically JSON) — “thin server” • Client-­‐side – MVVM JavaScript framework (Model-­‐View-­‐Viewmodel): AngularJS, Ember, Backbone, Knockout, … – Client-­‐side navigation logic, “single-­‐page application” – Consumes JSON data from the server • Typically still packaged together into a .war file using Maven 6
  • 7. Client-­‐side build tasks using Maven? Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • How do we do: – Client-­‐side library management analogous to Maven repositories? – Compilation of preprocessor languages like SASS, LESS – Compilation of languages like CoffeeScript, TypeScript? – Optimization of static files (concatenation, minification, compression, image sprites)? – Versioning of static resources to enable long-­‐term caching by browsers? – Unit testing and integration testing of JavaScript files? • And what is the overall development cycle? 7
  • 8. Introducing Grunt.js and Related Tools gruntjs.com Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 8
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. First, let’s talk about Node.js • JavaScript runtime for server applications, but also for command-­‐line apps • Includes node package manager (npm), online repository of packages • Packages installed globally or per-­‐project – Per-­‐project packages specified in package.json file • Platform-­‐specific installers available at nodejs.org – Installer adds node and npm commands on your system PATH • Tip: Use Node Version Manager (nvm) to manage Node.js distribution(s) – See https://github.com/creationix/nvm 9
  • 10. Next, we need to introduce Bower Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Package manager for the client-­‐side – Manages frameworks, libraries, assets, … – Supports various sources: git or svn repositories, download from URLs, archives, … – Controlled by bower.json (and .bowerrc) files • Install using npm, then use bower command: – npm install -g bower : installs bower as a global Node.js module! – bower install --save jquery : installs jQuery (latest version) to this project and adds an entry to bower.json – bower install : installs everything specified in bower.json 10
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. And finally, Grunt.js • JavaScript task runner — or simply a build tool • Install using npm: – npm install --save-dev grunt : installs Grunt in this project and saves it to the project’s package.json! – npm install -g grunt-cli : installs the Grunt command as a global Node.js module (and adds it to your PATH)! • Gruntfile.js defines and configures tasks 11
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Grunt plugins and tasks • Plugins provide predefined functionality and make it available as tasks • Installing a plugin: – npm install --save-dev grunt-usemin : installs/saves grunt-­‐usemin plugin (which provides useminPrepare and usemin tasks) in this project 12
  • 13. Configuring tasks and loading plugins in Gruntfile.js Copyright © 2014, Oracle and/or its affiliates. All rights reserved. grunt.initConfig({! usemin : {! options: {! dirs: ['dist']! },! html: ['dist/{,*/}*.html']! } ! });! ! // Load the plugin that provides the "usemin" task.! grunt.loadNpmTasks('grunt-usemin'); 13
  • 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Custom tasks, default task grunt.registerTask('clean-build',! 'Main clean/build task with SASS preprocessing.',! ['clean:all', 'build', 'sass']);! ! // Task to run when running ‘grunt’ without parameters! grunt.registerTask('default', ['clean-build']);! 14
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Grunt Tips // Time how long tasks take. Can help optimize build times.! require('time-grunt')(grunt);! ! // Load grunt tasks automatically! require('load-grunt-tasks')(grunt);! • You also need this in package.json: ! "devDependencies": {! "time-grunt": "^0.4.0",! "load-grunt-tasks": "^0.4.0",! } 15
  • 16. Moving from Maven to Maven + Grunt.js Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 16
  • 17. Changing the project’s source structure After (Maven + Grunt.js) project! !"# client! $ !"" bower_components! $ !"" node_modules! $ !"" public_html! $ !"" dist! $ !"" bower.json! $ !"" Gruntfile.js! $ %"" package.json! %"# server! !"" src! !"" target! %"" pom.xml! Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 17 Before (Maven) project! !"" src! !"" target! %"" pom.xml! ! • Sources moved from src/main/webapp to client/public_html! • Need CORS (cross-origin resource sharing) filter for development-time
  • 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Bower libraries downloaded to a separate staging area • Bower libraries copied to source tree – NetBeans recommended approach • SASS compilation • Unit testing 18 • Concatenation • Minification • Static resource revisions From Source to Production Development Environment Production Distribution Source
  • 19. Manage libraries using Bower Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Declare libraries in bower.json, instead of placing them directly under the web root • Copy them under e.g. public_html/libs/vendor using the bowercopy grunt task (from the grunt-­‐bowercopy node plugin) • Many Bower components contain “junk” other than the binary itself, so need to be careful what to copy 19
  • 20. Bundle client and server into a .war file Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Top-­‐level maven project called bundle (next to client and server) • pom.xml uses war packaging type • uses grunt-maven-plugin to call Grunt before packaging the result – https://github.com/allegro/grunt-­‐maven-­‐plugin 20
  • 21. Compilation, Minification, Unit testing, … Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 21
  • 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Compile SASS to CSS • Uses sass task (from the grunt-contrib-sass node plugin) ! sass: {! dist: {! files: {! 'main.css': 'main.scss',! 'widgets.css': 'widgets.scss'! }! }! } 22
  • 23. Minify and concatenate JavaScript and CSS Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Several tasks orchestrated by the grunt-usemin node plugin – useminPrepare prepares the configuration – concat concatenates files (usually JS or CSS). – uglify minifies JS files. – cssmin minifies CSS files. – filerev revisions static assets through a file content hash. – usemin replaces references in HTML files • Output should be written to a separate dist directory • copy task should copy all the other files from public_html to dist 23
  • 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Unit testing using Karma • place test sources under client/test (sibling of public_html) • karma.conf.js file controls the configuration of Karma • grunt-karma plugin provides karma task with several subtasks – grunt.registerTask('test', ['karma:run']); // PhantomJS! – grunt.registerTask('test-chrome', ['karma:run-chrome']);! – grunt.registerTask('test-coverage', ['karma:coverage']);! – grunt.registerTask('test-debug', ['karma:debug']); 24
  • 25. Development Cycle with Grunt.js and NetBeans IDE Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 25
  • 26. Development workflow from the command line Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • watch task (grunt-contrib-watch plugin) watches for changes in compiled files and recompiles them • Serve files using a lightweight web server • Reload files in the browser 26
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. NetBeans IDE • Great editor for JavaScript, HTML, CSS, SASS, LESS, … – Supports frameworks and libraries like require.js, AngularJS, Knockout, … • Running, debugging and Visual CSS editing not only on Chrome — also on iOS and Android devices and simulators – Including support for packaging applications using the Cordova framework • Built-­‐in lightweight web server, recompile and refresh browser on save • Built-­‐in test runner • … and many more features 27
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Resources • Grunt.js: gruntjs.com • Node.js: nodejs.org • Bower: bower.io • Karma: karma-­‐runner.github.io • SASS: sass-­‐lang.com • NetBeans IDE: netbeans.org • Project sources: https://github.com/pjiricka/affablebean-­‐maven-­‐grunt • Slides: http://www.slideshare.net/PetrJiricka 28