{"id":26052026,"url":"https://github.com/javaee-samples/javaee7-eclipse","last_synced_at":"2025-04-10T22:23:17.312Z","repository":{"id":21534400,"uuid":"24853873","full_name":"javaee-samples/javaee7-eclipse","owner":"javaee-samples","description":"Java EE 7 using Eclipse","archived":false,"fork":false,"pushed_at":"2015-03-12T04:43:21.000Z","size":222,"stargazers_count":15,"open_issues_count":0,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T19:21:49.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/javaee-samples.png","metadata":{"files":{"readme":"README.asciidoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-06T16:22:13.000Z","updated_at":"2023-08-25T11:06:00.000Z","dependencies_parsed_at":"2022-08-21T17:40:19.872Z","dependency_job_id":null,"html_url":"https://github.com/javaee-samples/javaee7-eclipse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javaee-samples%2Fjavaee7-eclipse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javaee-samples%2Fjavaee7-eclipse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javaee-samples%2Fjavaee7-eclipse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javaee-samples%2Fjavaee7-eclipse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javaee-samples","download_url":"https://codeload.github.com/javaee-samples/javaee7-eclipse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248307045,"owners_count":21081772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-08T05:47:23.056Z","updated_at":"2025-04-10T22:23:17.268Z","avatar_url":"https://github.com/javaee-samples.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Java EE 7 using Eclipse\n=======================\n\nProject creation\n----------------\n\n* Create a simple Dynamic Web Project\n** Choose the module version as ``3.1''\n** Add a new configuration for WildFly\n** Add `index.html` in ``WebContent''\n** ``Run as'', ``Run on Server''\n** Change content on `index.html` and show http://docs.jboss.org/tools/whatsnew/livereload/livereload-news-1.0.0.Alpha2.html[LiveReload]\n\nServlet\n-------\n\n* Add a new Servlet\n** In Servers tab, select the module, right-click and select ``Restart'' to restart the module\n** Show http://localhost:8080/HelloJavaEE7/TestServlet\n\nPersistence\n-----------\n\n* Right-click on project, select ``Properties'', search for ``facet'', enable ``JPA'', click on ``Apply''\n** Talk about ``Further configuration available'' and default data source (no configuration required)\n* Right-click on project, select ``New'', ``JPA Entity'' and give the name as `Student`\n* Add a primary key in the wizard. Use `long` datatype and `id` name.\n* Generate Getter/Setter by clicking ``Source'', ``Getters and Setters''.\n* Add `toString` implementation\n* The updated class should look like:\n+\n[source, java]\n----\n@Entity\n@XmlRootElement\n@NamedQuery(name=\"findAllStudents\", query=\"select s from Student s\")\npublic class Student implements Serializable {\n\t   \n\t@Id\n\tprivate long id;\n\tprivate static final long serialVersionUID = 1L;\n\n\tpublic Student() {\n\t\tsuper();\n\t}   \n\t\n\tpublic Student(long id) {\n\t\tthis.id = id;\n\t}\n\tpublic long getId() {\n\t\treturn this.id;\n\t}\n\n\tpublic void setId(long id) {\n\t\tthis.id = id;\n\t}\n\t\n\tpublic String toString() {\n\t\treturn \"Student[\" + id + \"]\";\n\t}\n}\n----\n+\n** `@XmlRootElement` in `Student` entity enables XML \u003c-\u003e Java conversion.\n** `@NamedQuery(name=\"findAllStudents\", query=\"select s from Student s\")` in `Student` enables querying all students.\n* Add the following properties to `persistence.xml`:\n+\n[source.xml]\n----\n\u003cproperties\u003e\n\t\u003cproperty name=\"javax.persistence.schema-generation.database.action\"\n\t\tvalue=\"drop-and-create\" /\u003e\n\t\u003cproperty name=\"javax.persistence.schema-generation.create-source\"\n\t\tvalue=\"metadata\" /\u003e\n\t\u003cproperty name=\"javax.persistence.schema-generation.drop-source\"\n\t\tvalue=\"metadata\" /\u003e\n\t\u003cproperty name=\"hibernate.show_sql\" value=\"true\"/\u003e\n\t\u003cproperty name=\"hibernate.format_sql\" value=\"true\"/\u003e\t\t\n\u003c/properties\u003e\n----\n+\n* Show ``server console'' when the application is deployed. Show the generated SQL statements.\n\nSetup console to watch database\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* Download\n  https://github.com/jboss-developer/jboss-eap-quickstarts/blob/6.3.0.GA/h2-console/h2console.war?raw=true[H2 console war] to WildFly's `standalone/deployments` directory\n+\n[source,text]\n----\ncurl -L https://github.com/jboss-developer/jboss-eap-quickstarts/blob/6.3.0.GA/h2-console/h2console.war?raw=true -o h2console.war\n----\n+\n* Start the server and access http://localhost:8080/h2console\n* Enter the JDBC URL and credentials. To access the \"test\" database your application uses, enter these details (everything else is default):\n** JDBC URL: `jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1`\n** User Name: `sa`\n** Password: `sa`\n\nRESTful Web Services\n--------------------\n\n* Create a JAX-RS resource `StudentEndpoint`\n** `rest.RestApplication` is added and specifies the base URI for REST resoures as `/rest`.\n** Use `Student` entity as the basis, select `create`, `findById`, `listAll` methods to be generated.\n* Update the class so that it looks like as shown:\n+\n[source,java]\n----\n@RequestScoped\n@Path(\"/students\")\npublic class StudentEndpoint {\n\t\n\t@PersistenceContext EntityManager em; \n\n\t@Transactional\n\t@POST\n\t@Consumes({ \"application/xml\", \"application/json\", \"text/plain\" })\n\tpublic void create(final long id) {\n\t\tStudent student = new Student(id);\n\t\tem.persist(student);\n\t}\n\n\t@GET\n\t@Path(\"/{id:[0-9][0-9]*}\")\n\t@Produces({ \"application/xml\", \"application/json\" })\n\tpublic Response findById(@PathParam(\"id\") final Long id) {\n\t\tStudent student = em.find(Student.class, id);\n\t\tif (student == null) {\n\t\t\treturn Response.status(Status.NOT_FOUND).build();\n\t\t}\n\t\treturn Response.ok(student).build();\n\t}\n\n\t@GET\n\t@Produces(\"application/xml\")\n\tpublic Student[] listAll(\n\t\t\t@QueryParam(\"start\") final Integer startPosition,\n\t\t\t@QueryParam(\"max\") final Integer maxResult) {\n\t\tTypedQuery\u003cStudent\u003e query = em.createNamedQuery(\"findAllStudents\", Student.class);\n\t\tfinal List\u003cStudent\u003e students = query.getResultList();\n\t\treturn students.toArray(new Student[0]);\n\t}\n}\n----\n+\n* Use ``Advanced REST Client'' in Chrome\n** Make a GET request to http://localhost:8080/HelloJavaEE7/rest/students\n*** Add Accept: application/xml\n*** Show empty response\n** Make a POST request\n*** Payload as `1`\n*** ``Content-Type'' header to `text/plain`\n** Make a GET request to validate the data is posted\n* Edit `doGet` of `TestServlet` to match the code given below\n+\n[source,java]\n----\nServletOutputStream out = response.getOutputStream();\nout.print(\"Retrieving results ...\");\nClient client = ClientBuilder.newClient();\nStudent[] result = client\n.target(\"http://localhost:8080/HelloJavaEE7/rest/students\")\n.request()\n.get(Student[].class);\nfor (Student s : result) {\n\tout.print(s.toString());\n}\n----\n* Access the Servlet in the browser to show the results and explain JAX-RS Client API\n\n\nBean Validation\n---------------\n\n* Change `create` method to add Bean Validation constraint\n+\n[source,java]\n----\npublic void create(@Min(10) final long id) {\n----\n+\n* Make a POST request with payload as `1` and show an error is being received\n\n\nCDI\n---\n\n* Generate an interface `Greeting`\n+\n[source,java]\n----\npublic interface Greeting {\n\tpublic String sayHello();\n}\n----\n+\n* Create a new class `SimpleGreeting`, implement the interface as:\n+\n[source, java]\n----\npublic class SimpleGreeting implements Greeting {\n\n\t@Override\n\tpublic String sayHello() {\n\t\treturn \"Hello World\";\n\t}\n\n}\n----\n+\n* Inject the bean in Servlet as `@Inject Greeting greeting;`\n* Print the output as `response.getOutputStream().print(greeting.sayHello());`\n* Show ``New missing/unsatisfied dependencies'' error and explain default injection\n* Add `@Dependent` on bean\n* Create a new class `FancyGreeting`, implement the interface, add `@Dependent`\n* Create a new qualifier using ``New'', ``Qualifier Annotation Type''\n\nAdvanced CDI\n------------\n\n* Wizards:\nhttp://docs.jboss.org/tools/4.1.x.Final/en/cdi_tools_reference_guide/html/chap-CDI_Tools_Reference_Guide-Creating_a_CDI_Web_Project.html[New CDI Web Project Wizard],\nhttp://docs.jboss.org/tools/4.1.x.Final/en/cdi_tools_reference_guide/html/chap-CDI_Tools_Reference_Guide-Wizards_and_Dialogs.html#d0e555[CDI Wizards]\n* Content assist: CDI Named Beans are available in JSF EL #{} content assist in XHTML/Java/XML files (See JSF)\n* Validation:\nhttp://docs.jboss.org/tools/4.1.x.Final/en/cdi_tools_reference_guide/html/chap-CDI_Tools_Reference_Guide-Validation.html\n* Navigation (open the bean producer from the @Inject annotation for example):\nhttp://docs.jboss.org/tools/4.1.x.Final/en/cdi_tools_reference_guide/html/chap-CDI_Tools_Reference_Guide-Hyperlink_Navigation.html[Java source navigation], from EL #{} to CDI bean (See JSF)\n* Open CDI Named bean: http://docs.jboss.org/tools/4.1.x.Final/en/cdi_tools_reference_guide/html_single/index.html#d0e597\n* Beans.xml editor: Content assist, Navigation, Validation\nhttp://docs.jboss.org/tools/whatsnew/cdi/cdi-news-3.2.0.Beta1.html\n* Search usage: https://issues.jboss.org/browse/JBIDE-8705[Injection Points], EL #{} (See JSF)\n* CDI 1.2 support was introduced in JBoss Tools 4.3.0.Alpha1: http://tools.jboss.org/documentation/whatsnew/jbosstools/4.3.0.Alpha1.html#cdi\nBut it's mostly about showing CDI 1.2 as available in our wizards (New CDI Project wizard for example) + minor bug fixing. In JBoss Tools 4.2 (Eclipse Luna) you can use CDI 1.1 in wizards for CDI 1.2 projects since 1.2 is just a maintenance release and CDI Tools relays on actual CDI jars from the project's class path. \n\nBatch\n-----\n\n* Open https://github.com/javaee-samples/javaee7-samples/[Java EE 7 Samples project] and show Job XML\n* http://tools.jboss.org/documentation/whatsnew/jbosstools/4.3.0.Alpha1.html#batch[Batch job XML editor] - available in JBoss Tools 4.3.0.Alpha1\n* Upcoming 4.3.0.Alpha2 features: Validation, Content Assist, Navigation, - https://issues.jboss.org/browse/JBIDE-18857\n\nJavaServer Faces\n----------------\n\n* EL content assist in XHTML: http://docs.jboss.org/tools/whatsnew/jst/jst-news-3.3.0.M3.html\n* Navigation from/to bean\n* Search usage\n* Refactoring:\nhttp://docs.jboss.org/tools/whatsnew/jst/jst-news-3.2.0.M1.html\n* New JSF project wizard (JSF 2.2 or older)\n* Composite component code assist:\nhttps://issues.jboss.org/browse/JBIDE-4970, http://docs.jboss.org/tools/whatsnew/jst/jst-news-3.2.0.Beta2.html, Validation and refactoring are also available\n* EL Validation: http://docs.jboss.org/tools/whatsnew/jst/jst-news-3.2.0.M2.html\n\nOpenShift\n---------\n\n* Create a new server adapter from ``OpenShift Explorer''\n* More details at http://blog.arungupta.me/getting-started-wildfly-openshift-jboss-developer-studio/\n\nForge\n-----\n\n* Switch to JBoss perspective\n* Go to ``Forge Console'', click on play button to start it\n* `project-new --named sample`\n* `javaee-setup --javaEEVersion 7`\n* `jpa-setup --jpaVersion 2.1`\n* Install plugin: `addon-install-from-git --url https://github.com/forge/addon-batch`\n** Create new Job XML: `batch-new-jobxml --jobXML myJob.xml --reader org.svcc.MyReader --writer org.svcc.MyWriter`\n* More details about Batch and Forge at: http://blog.arungupta.me/javaee7-batch-addon-jboss-forge-part1/\n* More details about other technologies at: http://blog.arungupta.me/rapid-javaee-development-forge2/\n\nContinuous Delivery\n-------------------\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavaee-samples%2Fjavaee7-eclipse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavaee-samples%2Fjavaee7-eclipse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavaee-samples%2Fjavaee7-eclipse/lists"}