tooling support for enterprise development - WordPress.com

6 downloads 77 Views 9MB Size Report
features makes Java EE development fast, easy, and clean. (maintainable). • It is Java ... JBoss Tools – extends Eclipse's Java EE capabilities. • JRebel – greatly ...
TOOLING SUPPORT FOR ENTERPRISE DEVELOPMENT R YA N C U P R A K & R E Z A R A H M A N

JAVA EE DEVELOPMENT •  Java EE has had a bad reputation: •  •  •  •  •  • 

Too complicated Long build times Complicated/expensive tooling Copious amounts of repetitive code Expensive application servers Overkill for most projects

•  Times have changed since 2000!

•  Java EE 5 made great strides leveraging new features introduced in Java 5. Java EE 6 pushes us forward. •  Excellent tooling support combined with a simplification of features makes Java EE development fast, easy, and clean (maintainable).

•  It is Java EE – NOT J2EE!!!

OBJECTIVE Challenge: Starting a new project is often painful. In this presentation you’ll learn: •  How to setup a new Java EE project. •  Disconnect between theory and practice. •  Tools that you should consider learning/adding. •  Best practices for Java EE development from tools side.

When is the last time you evaluated your tools?

APPLICATION TYPES Types of Java EE applications: •  Prototype – verify technology, try different techniques, learn new features. •  Throw-away – application which has a short-life space, temporary use. •  Internal/external portal – application with a long life expectancy and which will grow over time. •  Minimize dependence on tools.

•  Product – an application which deployed at a more than one customer site. Possibly multiple code branches. •  Minimize dependence on tools.

Life expectancy drives tooling decisions.

PRELIMINARIES Considerations for a Java EE toolbox: •  Build system: Ant, Maven, IDE specific? •  Container: GlassFish/JBoss/ WebLogic/etc. •  Technologies: EJB/JPA/CDI/JSF •  IDE: Eclipse, NetBeans, IntelliJ IDEA •  Other tools: Unit testing, integration testing, UI testing, etc.

IDES •  NetBeans •  Easy to use Java EE templates. •  Includes a pre-configured GlassFish container. •  Support for bleeding edge Java EE features.

•  IntelliJ •  Excellent editor support – auto-completion and analysis. •  Support for complex project structures. •  Support for a myriad of web technologies.

•  Eclipse •  Wide industry adoption. •  External Java EE tools from JBoss. •  External plugins – large ecosystem.

If exploring Java EE, start with NetBeans.

ADD-ON TOOLS Beyond the IDE:

•  JBoss Tools – extends Eclipse’s Java EE capabilities. •  JRebel – greatly speeds deployments so that you only swap in the code that changes. http://zeroturnaround.com/ •  Arquillian – integration testing – enables EJBs to be tested an in embedded Java EE container (GlassFish/JBoss etc.). http://www.jboss.org/arquillian.html •  Liquidbase – “version control” for database schemas – important for applications that are going to grow over time. http://www.liquidbase.org •  JMeter – web application stress testing tool (http://jmeter.apache.org). •  Hudson/Jenkins – continuous integration (http://hudson-ci.org). •  Selenium – functional web UI testing (http://seleniumhq.org). •  SOAP UI – testing SOAP/rest web services (http://www.soapui.org). •  Monitoring Tools – NAGIOS/HP OpenView/IBM Tivoli/Oracle Enterprise Management Tools •  Profiling – NetBeans Profiler/Jprofiler/VisualVM/etc.

Impossible to cover everything.

BUILD SYSTEMS Ant

Maven

•  Pro: •  Infinitely flexible – write once. •  Integrated support with most IDEs.

•  Cons •  No defined project standard •  Maintenance headache •  IDE integration.

•  Pro •  Standard project layout •  Dependency management •  Supported by all IDEs

•  Cons •  Steep learning curve •  Harder to customize •  Build cycle-time (lacks incremental compilation)

BUILD SYSTEM IDE

Hybrid (bad idea):

•  Pro •  Fast build/deployment •  GUI management

•  Cons •  Not portable •  Continuous integration support

•  Pro •  Fast build times •  Tool independence

•  Cons •  Twice the work

JAVA EE PACKAGING Traditional EE:

XML META-INF EAR (.ear)

EJB-JAR (.jar) XML application.xml

ejb-jar.xml

XML EJB 1

persistence.xml

XML

EJB 1

beans.xml

XML

WAR (.war)

WEB-INF web.xml

lib dependency 1.jar

dependency 2.jar

index.xhtml

SIMPLIFIED JAVA EE PACKAGING Simplified EJB packaging (WAR): WEB-INF

classes

WAR (.war)

EJB 1

XML

index.xhtml

web.xml

XML

login.xhtml

beans.xml

XML

faces-config.xml XML persistence.xml

Introduced in EJB 3.1

EJB 2

CONFIGURATION FILES beans.xml

web.xml ejb-jar.xml

application.xml persistence.xml

faces-config.xml

PACKAGING & CONFIGURATION Tooling challenge – how do you: •  Create a new project scratch? •  Import an existing project? •  Create valid Java EE configuration files? •  Edit Java EE configuration files? •  Navigate Java EE features effectively? •  Manage the evolution of a project and Java EE technology changes?

IDES •  Leading Java IDEs: •  NetBeans 7.2 •  IntelliJ IDEA 11 •  Eclipse Juno

•  Is one IDE better than the others?

•  NO! Each has a unique set of features.

•  What are the major differences: •  •  •  • 

Available project templates Supported containers Setup/external libraries Ease of use

•  Unique features:

•  NetBeans: Profiling, Hudson integration, CDI, HTML5, JavaFX, etc. •  IDEA: Code inspection/completion, SOAP UI, Android, Flash/Flex, SQL/ JavaScript editor, etc. •  Eclipse: BIRT, Perspectives, GWT, AspectJ, JBoss Tools, gigantic unique of add-ons.

IDES Key features to consider: •  Project creation/management (wizards) •  Container integration (launching/ deploying/debugging)

•  Generating/checking configuration files •  Generating entities/CRUDs •  Embedded libraries •  JQL query code completion/ verification •  EL code completion (CDI support) •  CDI/JSF/JPA validation/error detection

IDEA •  JetBrains IDEA – two editions: •  Community – core Java development (free) •  Ultimate – support for enterprise technologies (purchase $199 personal license/$99 academic) •  Support for running in application servers. •  CDI/JPA coding support etc.

•  Ultimate edition needed for Java EE development.

IDEA IDEA build system support: •  Build system options with IDEA: •  Maven – supported project type •  IDEA specific

•  IDEA uses its own build system by default. •  Drawbacks:

•  Other developers must use IDEA to compile/package •  Cannot integrate into continuous integration services such Hudson, CruiseControl, etc.

•  Benefits:

•  Optimized for fast builds and incremental compiling •  Tight integration with IDEA – complete management in UI.

•  Options:

•  Create an Ant build file: Build | Generate Ant Build… •  Create project using Maven •  Create a Maven project using mvn idea:idea

IDEA •  Before creating a project: •  Configure the application server you are going to be using. •  Create data sources in IDEA for a database.

•  Supported containers: •  •  •  •  •  •  •  • 

Apache Tomcat (4.0-7.0) WebLogic (7.0-12.1.1) WebSphere (5.1-8.0) JBoss (4.2-7.0.2) GlassFish (2-3) Resin (3-4) Jetty (6-8.1) JSR45 Compatible server

•  Container can be either local or remote

IDEA •  Important concepts:

•  Project – organizational unit that represents a complete solution. It is composed of modules. •  Module – discrete unit of functionality with can be compiled/ run/tested independently. (WAR/EJB JAR) •  Facets – represents a framework/technology/language used in a module. (CDI/JSF/JPA)

•  Two project formats:

•  Directory based: .idea

•  Configuration settings are stored in separate XML files (compiler.xml, encoding.xml, etc.) •  workspace.xml should not be stored in VCS.

•  File based:

•  .ipr – project settings to be stored in VCS. •  .iws – machine specific settings – do not put in VCS.

IDEA •  Java EE Projects: •  No pre-defined Java EE templates. •  Three starting points: •  New project from scratch •  Create from external model (Maven/Eclipse/Gradle) •  Existing sources (ignores build file)

•  Add facets/frameworks for Java EE features. •  Configure artifacts to define Java EE packaging. •  Create a Project and a Module.

IDEA New Project Wizard Pick Java Module

•  •  •  •  •  •  •  •  • 

Java Web Plugin J2ME Flash Maven Grails Griffon Android

Configure technologies

Java EE Pertinent •  Web Application •  Struts •  JSF •  Struts 2 •  Application Server •  EJB •  Java EE Application •  Java EE Persistence •  Hibernate •  SQL Support

Configure Facets

•  •  •  •  •  •  •  •  • 

JPA CDI EJB GWT JRebel JSF Seam Struts etc.

Configure Artifacts

•  •  •  • 

WAR EAR JAR Exploded

IDEA

DEMO

IDEA Wizard Summary •  Wizard creates a single module project. •  Project uses the technologies that you selected. •  Downloads Java EE dependencies. Important •  Additional modules can be created after the project is created. •  Don’t select all of the technologies if creating an EAR!!

•  Wizard does not create a “EAR” project with multiple modules.

IDEA What have we accomplished? •  Created a new IDEA project from scratch. •  Single enterprise web module •  Downloaded and configured CDI. •  Added facets for CDI, JPA, and EJB. •  Deployed the application to GlassFish. Challenges: •  Container installation performed separately. •  Libraries had to be downloaded separately. •  Config files must be created separately. •  Required project setup post configuration.

NETBEANS •  Excellent support for Java EE. •  Java EE support is not a separate download (features can be activated). •  3 Java web templates: •  Web Application – supports CDI/EJB (simplified project) •  Web Application with Existing Sources •  Web Free Form Application

•  6 Java EE templates: •  •  •  •  •  • 

Enterprise Application Enterprise Application with Existing Sources EJB Module EJB Module with Existing Sources Enterprise Application Client Enterprise Application Client with Existing Sources

NETBEANS •  Full support for Java EE 6 •  Integrated IDE support for CDI •  Service integration/monitoring: •  Database editor •  Container integration: •  •  •  • 

•  •  •  • 

Tomcat GlassFish JBoss WebLogic

JPA support Web Services (consume/produce) JSF support Integration with Hudson

NETBEANS NetBeans Java EE File Templates

NETBEANS Service integration:

GlassFish Server Deployed application

JDBC Resources Deployed web services Hudson servers

NETBEANS •  NetBeans doesn’t have the concept of ‘modules’. •  “Modules” concept from IntelliJ/Maven are represented as separate NetBeans projects.

•  Projects can depend upon other projects. •  Dependencies are not exported! •  Project must produce an artifact.

•  Projects types: •  Standard projects – use NetBeans generated Ant build file. •  Maven projects – use Maven natively. •  Free-form projects – delegate to custom Ant file.

•  Ant/Maven native projects – no custom build system.

NETBEANS Choosing a project template: Existing project? Yes Existing build? Yes Java Free Form Project

No Ant or Maven?

No Java project with existing sources

ANT Java project template

Maven Maven project template

IDEA

DEMO

NETBEANS Output: ctjava.ear

Ctjava-ejb.jar

Ctjava-war.jar

NETBEANS Customizing Ant build:

NETBEANS NetBeans specific files: •  .nbproject contains project related settings. •  .nbproject/private contains local settings that should not be checked in VCS. •  build.xml contains is the modifiable Ant build file. •  build-impl.xml should never be edited, changes/ overrides belong in build.xml.

NETBEANS Differences between IntelliJ and NetBeans: •  Many pre-defined project templates to simplify initial project creation. •  No need to download a CDI implementation. •  Still must create a beans.xml configuration file to use CDI.

•  GlassFish comes pre-packaged with NetBeans and pre-configured. •  Smaller subset of supported containers. •  NetBeans has numerous templates to simplify basic tasks. •  Integrated support for Ant.

ECLIPSE •  Eclipse IDE for Java EE provides numerous Java EE templates and plug-ins. •  Java EE Projects: •  •  •  •  •  • 

Application Client Project Connector Project Enterprise Application Project Utility Project EJB Project JPA Project

ECLIPSE •  JBoss Tools – invaluable collection of tools. •  Available through MarketPlace or directly: http://www.jboss.org/tools •  Greatly expands Eclipse’s baseline Java EE support: •  Maven/git •  CDI •  Templates and wizards for EJB, Web Services (SOAP/REST), JSF configuration, SEAM, etc.

•  Tools are a necessity for Java EE developers using Eclipse.

ECLIPSE

DEMO

MAVEN •  Maven is much more than a build tool. •  Provides a standard layout to projects. •  Dependency management.

•  Supported as a project type by all IDEs: •  Seamless support (no need for a plugin): •  NetBeans •  IntelliJ IDEA

•  Plugin required (provided by JBoss tools): •  Eclipse

•  Maven is IDE independent – can move between IDEs easily.

MAVEN •  Pre-configured archetypes in NetBeans & Eclipse.

MAVEN Create Java EAR project: mvn archetype:generate -DgroupId=org.ctjava -DartifactId=portal -DarchetypeArtifactId=jboss-javaee6-ear-webapp -DarchetypeGroupId=org.jboss.spec.archetypes

portal

portal-ear

portal-ejb

portal-web

MAVEN IDE support: •  IDEA: •  Built-in support for Maven •  Open existing Maven project – no support for creating a new Maven Java EE project.

•  NetBeans: •  Built-in support for Maven. •  Open existing Maven projects. •  Create new Java EE Maven projects using wizards.

•  Eclipse: •  No Maven support-out of the box. •  Download JBoss tools for Maven support

ARQUILLIAN Basics •  JBoss Arquillian automates in-container testing. •  EJB and CDI code can be tested – code that uses JPA, invokes EJBs, etc. •  Integration tests are run inside of a container such as GlassFish, JBoss. •  Integrates with Selenium available. •  Can perform regression performance tests. •  Less painful when using Maven.

ARQUILLIAN Maven configuration:

ARQUILLIAN •  Supporting artifacts: •  arquillian.xml – specifies domain.xml for GlassFish. •  domain.xml – custom GlassFish configuration file. •  web.xml – custom web app configuration file.

ARQUILLIAN

LIQUIBASE Database Schema Versioning •  JPA handles object relational mapping but how are the database schema being managed?

•  Could you replicate the current database schema in production? •  Could you recreate a database schema required for a specific code tag? •  How do you “upgrade” a database schema to a new version?

Liquibase •  Tool for tracking and managing database changes. •  Open source project. •  http://www.liquibase.org •  Command line tool •  Changes tracked in a change log, store in EAR/WAR.

LIQUIBASE changelog.xml tracks database operations.

LIQUIBASE Changes are tracked in the database.

SUMMARY •  Explorations and Java EE prototypes:

•  Use NetBeans to explore Java EE and create new projects.

•  Large projects:

•  Use Maven as the build system. •  •  •  • 

Dependency management. Standard project layout. Profiles to build sub-systems. IDE independence – mix and match IDEs for different features.

•  Modularize the system into manageable chunks. •  Use Arquillian for integration testing – unit testing isn’t enough for large applications. •  Use JRebel to reduce deployment times. •  Use Liquibase to manage database changes.

•  Invest in tooling!

•  Don’t forget there is NetBeans Certification! Re-evaluate your tools regularly!

Q&A

Suggest Documents