{"id":21911815,"url":"https://github.com/amiteshhh/demomavenwebproject","last_synced_at":"2026-04-08T18:07:00.037Z","repository":{"id":122150486,"uuid":"87296394","full_name":"amiteshhh/DemoMavenWebProject","owner":"amiteshhh","description":"Integrating node project into Java Project using Maven","archived":false,"fork":false,"pushed_at":"2017-04-20T07:04:26.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-25T09:27:06.762Z","etag":null,"topics":["front-end-development","grunt","java","maven","nodejs","war"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/amiteshhh.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-05T10:22:37.000Z","updated_at":"2017-04-19T18:30:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"59fe2b96-5947-4337-b437-109159e599fe","html_url":"https://github.com/amiteshhh/DemoMavenWebProject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amiteshhh/DemoMavenWebProject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiteshhh%2FDemoMavenWebProject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiteshhh%2FDemoMavenWebProject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiteshhh%2FDemoMavenWebProject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiteshhh%2FDemoMavenWebProject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amiteshhh","download_url":"https://codeload.github.com/amiteshhh/DemoMavenWebProject/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiteshhh%2FDemoMavenWebProject/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31567356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["front-end-development","grunt","java","maven","nodejs","war"],"created_at":"2024-11-28T18:07:43.260Z","updated_at":"2026-04-08T18:06:59.999Z","avatar_url":"https://github.com/amiteshhh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sample maven project\n\nThis project demonstrate how you can integrate the [node](https://nodejs.org/) based build system into [maven](https://maven.apache.org/) using maven plugin [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin).\n\n## Overview\n\nFront end developer prefers the _node_ based ecosystem which comes with many handy tools like [npm](https://www.npmjs.com/), [Grunt](http://gruntjs.com/), [Gulp](http://gulpjs.com/) and many more to manage application development, code validation, test automation, optimization, deployment etc.\n\nHowever If you want to integrate it into Java Project to deploy it as a [WAR](https://en.wikipedia.org/wiki/WAR_(file_format)) , you must put the entire front-end code-base into appropriate directory of Java project (normally under `WebContent` or `webapp` folder). Unfortunately Java build system doesn't have inbuilt support to invoke _node_ commands and therefore you will not only lose the various optimization, validations that you were able to do in _node_ ecosystem but also it will look ugly and unmanageable to put everything inside `webapp` directory.\n\n\u003eManually copying the the optimized/compiled/validated front-end code to appropriate directory of Java project is time consuming and painful.\n\n## Solution\n\nFortunately there are many maven plugins available which can run the _node_ command. One such plugin is [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin).\n\nThis plugin downloads/installs Node and NPM locally for your project, runs npm install, and then any combination of Bower, Grunt, Gulp, Jspm, Karma, or Webpack.\n\nAll we need to do is additionally write appropriate grunt/gulp task to copy the front-end code to appropriate Java directory( `webapp` folder in maven based project)\n\n## Example\n\nThis sample project is built using maven and Grunt for client task automation.\n\n### __Step 1:__ Dynamic Java Website Project Creation Using Maven\n\u003e Skip if you have already done.\n\nI will be using `maven` command to create a Maven Project. You can also use `eclipse` to create Maven project. \n\nRun command in the directory under which you want to keep your project\n\n`mvn archetype:generate -DgroupId=com.demo.java -DartifactId=DemoMavenWebProject -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false`\n\nThis will create a project with folder named `DemoMavenWebProject`\nRefer Maven directory structure for detail\n\n```\n├── DemoMavenWebProject/\n│   └── src/\n│       └── main/\n│           └── webapp/\n│   └── pom.xml\n\n```\n\n### __Step 2:__ Create the front-end node project \n\nPreferebly create a folder named `client` under root folder `DemoMavenWebProject` and put all your client code inside this. \n\n### __Step 3:__ Create Grunt task to  be run during maven build\n\nGrunt task has been created to concatanate, minify and uglify the source code into `dest` directory along-with copying static assets.\n\nDuring maven build we will do all this and copy the `dest` directory content into `webapp` directory using `copy:mvn` task.\n\n \n```js\ngrunt.registerTask('default', ['clean:build', 'copy:staticFiles', 'min-build']);\ngrunt.registerTask('build', ['default']);\ngrunt.registerTask('mvn-build', ['build', 'clean:mvn', 'copy:mvn']);\n\n```\n\n\u003e The Grunt task is minimal as our primary concern is to integrate it into maven.\n\n### __Step 4:__ Install `grunt-cli` locally\n\nSince maven plugin runs the command in local _node_ environment `grunt-cli` must be a part of the node project so that it can recognize `grunt` command.\n\nUse `npm install grunt-cli --save-dev` to save it as a project dependency.\n\n### __Step 5:__ Modify `pom.xml` to include the Grunt automation\n\nThis step is really simple. We just need to create a maven `\u003cprofile\u003e` in the _pom.xml_ and mention the task which we want to execute.\nRefer _pom.xml_ of the project or see the [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin) documentation. \n\nHere is an equivalent setup to invoke `grunt mvn-build` command from maven.\n\n```xml\n\u003cexecution\u003e\n    \u003cid\u003egrunt build\u003c/id\u003e\u003c!-- just a name --\u003e\n    \u003cgoals\u003e\n        \u003cgoal\u003egrunt\u003c/goal\u003e\u003c!-- command --\u003e\n    \u003c/goals\u003e\n    \u003cconfiguration\u003e\n        \u003carguments\u003emvn-build\u003c/arguments\u003e \u003c!-- command argument--\u003e\n    \u003c/configuration\u003e\n\u003c/execution\u003e\n\n```\n\n\u003e Since Grunt itself depends on node and npm we must setup maven to install that prior to invoking this command.\n\n\u003e`frontend-maven-plugin` plugin does not support already installed Node or npm versions. This is partly because the build should not be affected if run in different machines.\n\nPlugin create a folder `node` inside `client` directory to setup the local node and npm.\n\nYou can manually copy _node.exe_ in the `node` directory and maven will take it up from there instead of downloading it from server.\n\n### __Step 5:__ Build Project using maven\n\nFor this project I have created a _profile_ `fullBuild` in _pom.xml_ to run the Grunt Task, copy the minified code into `webapp` and generate the [WAR](https://en.wikipedia.org/wiki/WAR_(file_format)) to deploy it over server.\n\nRun the command `mvn clean install -P fullBuild`\n\n\n## Maven Troubleshoot\n\n__1) mvn command not working__\n\n- Ensure that Maven `bin`  and `jdk` directory added to system/user environment _path_ variable\n- Create `JAVA_HOME` environment variable pointing to `jdk` directory.\n\n__2) mvn command unable to download the package due to proxy__\n\n- Ensure that maven repository is accessible through Browser to rule out url blockage.\n- If you are behind proxy, configure proxy as described below\n\n    Maven download the package in a special folder `.m2` in the user home directory (typically `C:\\Users\\[Your_User_Id]\\.m2` folder).\n    Create/Edit the file `settings.xml` inside it to add proxy and repositories detail.\n    \n    Refer the sample [Gist](https://gist.github.com/amiteshhh/629e9a3a49e035a6d0709172eb435145) and [Maven proxy configuration](https://maven.apache.org/guides/mini/guide-proxies.html) documentation for `settings.xml` details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famiteshhh%2Fdemomavenwebproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famiteshhh%2Fdemomavenwebproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famiteshhh%2Fdemomavenwebproject/lists"}