简体   繁体   English

具有Node.js,Angular,Karma,Jasmine和Maven的Java动态Web项目

[英]Java Dynamic Web Project with nodejs, angular, karma, jasmine and maven

I have a question related to best practice folder structure for a WEB-APPLICATION (Mobile compatible as well). 我有一个与WEB-APPLICATION(以及移动设备兼容)的最佳实践文件夹结构有关的问题。 I know this is opinion based question. 我知道这是基于意见的问题。 But I did not find any good solution over internet. 但是我在互联网上找不到任何好的解决方案。 So I thought it will worth to post it here. 所以我认为值得在这里发布。

Since my project is Java based backend. 由于我的项目是基于Java的后端。 So I created a dynamic web project from Eclipse with maven functionalities. 因此,我从Eclipse创建了一个具有maven功能的动态Web项目。

So my folder structure is just as follows. 所以我的文件夹结构如下。

SampleProkject
|
|-----src
      |
      |---- main
             |----java
             |----resources
             |----webapp
      |
      |---- test
             |---java
             |---resources

My all Java backend related code goes to src/main/java 我所有与Java后端相关的代码都转到src/main/java

and All HTML, CSS and JS goes to src/main/webapp 并且所有HTML,CSS和JS都转到src/main/webapp

Similarly all my test classes for java goes to src/test/java 同样,我所有的Java测试类都转到src/test/java

From Java perspective everything is fine but problem comes when I try to places my angular files. 从Java的角度来看,一切都很好,但是当我尝试放置角度文件时出现了问题。

Since I am using npm to install all required js files and frameworks. 由于我正在使用npm安装所有必需的js文件和框架。 I placed package.json inside my webapp. 我将package.json放在我的web应用程序中。 So node_modules is also being created inside my webapp . 因此,也在我的webapp中创建了node_modules Which is I do not want because node_modules is just for dependency so I do not want to expose it over HTTP. 我不希望这样,因为node_modules仅用于依赖关系,所以我不想通过HTTP公开它。 So I need to place my package.json outside of webapp. 所以我需要将package.json放在webapp之外。 But then I can not use node_modules in index.html file because it can not access files out side of webapp. 但是然后我无法在index.html文件中使用node_modules,因为它无法访问webapp之外的文件。

Also I do not want to place my test cases (Karma.conf.js and Jasmine test suits) to webapp. 另外,我也不想将测试用例(Karma.conf.js和Jasmine测试服)放置到webapp中。 So what I did I place those to src/test/javascript. 所以我将它们放在src / test / javascript中。

Now the thing is I have to access all my angular code and node_modules from src/test/javascript and also from webapp/index.html file. 现在,我必须从src / test / javascript以及从webapp / index.html文件访问我的所有角度代码和node_modules。

Please suggest a best approach. 请提出最佳方法。 I think several Java developer who are using angular with nodejs for UI, facing same issues. 我认为有几位Java开发人员正将nodejs与nodejs一起使用,面临同样的问题。

Note : 注意事项

Actually I am looking for a good project structure with maven, java, nodejs and angular. 实际上,我正在寻找具有maven,java,nodejs和angular的良好项目结构。 Which also include Java and Angular unit testes as well. 其中也包括Java和Angular单元测试。

There are many maven archtypes and yeoman generators available. 有许多Maven原型和yeoman生成器。 But if want a good base application using angular as front end and spring/java as backend, go see http://jhipster.github.io/ 但是,如果要使用Angular作为前端和spring / java作为后端的良好基础应用程序,请访问http://jhipster.github.io/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM