问题描述
使用 Netbeans 8.2,我创建了一个新的 MAVEN Web 应用程序.我在 Web Pages
文件夹中放置了一个有效的 package.json
文件,所以它的路径是
C:\Users\xxx\Documents\NetBeansProjects\MyApp\src\main\webapp\package.json
我左键单击 package.json
文件,然后单击 npm install
选项.然后我收到了这些错误/警告
"C:\Program Files\nodejs\npm.cmd" "安装"npm WARN ENOENT ENOENT:没有这样的文件或目录,打开C:\Users\Nick\Documents\NetBeansProjects\MyApp\package.json"npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp 没有描述npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp 没有存储库字段.npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp 没有 README 数据npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp 没有许可证字段.完毕.
我注意到 Netbeans 试图在错误的位置寻找 package.json
C:\Users\Nick\Documents\NetBeansProjects\MyApp\package.json'
而且我似乎不知道如何告诉 IDE 去哪里寻找它.
当我去
项目属性 > JavaScript 库 > npm
我用
得到一个空视图找不到package.json
我的问题是,如何设置 netbeans 以查看package.json"并运行它?当我尝试在 HTML5 项目中使用它时,它运行良好,但我需要对 Java Web 应用程序项目的 npm 支持.
我回答我自己的问题真的很晚,但我最终找到了内置 IDE 机制之外的解决方案.我使用
然后插件将运行并安装一个 package.json
和一个节点运行时在一个单独的目录中,该目录不会与您的项目捆绑在一起,您可以在那里编辑它并重新运行目标.
Using Netbeans 8.2, I've created a new MAVEN web application. I have placed a working package.json
file inside the Web Pages
folder so it's path is
I left click on the package.json
file and click the npm install
option. I was then greeted by these errors/warnings
"C:\Program Files\nodejs\npm.cmd" "install"
npm WARN ENOENT ENOENT: no such file or directory, open 'C:\Users\Nick\Documents\NetBeansProjects\MyApp\package.json'
npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp No description
npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp No repository field.
npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp No README data
npm WARN EPACKAGEJSON C:\Users\xxx\Documents\NetBeansProjects\MyApp No license field.
Done.
I noticed Netbeans attempted to look for the package.json at the wrong place
And I can't seem to figure out how to tell the IDE where to look for it.
When I go to
I get an empty view with
My question is, how can I setup netbeans to see that 'package.json' and run it? It worked fine when I tried using it in a HTML5 project, but I need npm support for a Java web app project.
I'ts really late to answer my own question but I eventually found a solution outside the the builtin IDE mechanics. I used the frontend-maven-plugin to setup a local npm repo for my project.Than instead of using the npm install
option given by the IDE, I used maven to define a goal, and run it using nbactions.xml
.
To install the plugin, edit your
pom.xml
(snippet from here), add the plugin descriptor and the execution that will download and install npm inside your repo<plugins> <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.8.0</version> <executions> <!-- Installs node + npm in your repo --> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <phase>generate-resources</phase> </execution> ...
I've appended this code to the one above, it's an execution that runs
npm install
(snippet found here).... <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> <!-- optional: default phase is "generate-resources" --> <phase>generate-resources</phase> <configuration> <!-- optional: The default argument is actually "install", so unless you need to run some other npm command, you can remove this whole <configuration> section. --> <arguments>install</arguments> </configuration> </execution> </plugin>
Create a
package.json
file (in the same directory where your pom is) and start putting stuff into it (example)I've added a reference to the
npm install
goal insidenbactions.xml
, I've gave it a display name ofnpm-install
</actions> ... <action> <actionName>CUSTOM-npm-install</actionName> <displayName>npm-install</displayName> <goals> <goal>npm</goal> </goals> </action> </actions>
Then, right click on the Project (from the projects view) -> Run Maven -> npm-install
The plugin will then run and install a package.json
and a node runtime in a seperate directory that won't be bundled with your project, you can edit it there and re-run the goal.
这篇关于Netbeans 无法在 MAVEN Web 应用程序上运行 package.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!