更新时间:2023-10-21 13:04:16
我回答我自己的问题真的很晚,但我最终找到了内置 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
C:\Users\xxx\Documents\NetBeansProjects\MyApp\src\main\webapp\package.json
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
C:\Users\Nick\Documents\NetBeansProjects\MyApp\package.json'
And I can't seem to figure out how to tell the IDE where to look for it.
When I go to
Project Properties > JavaScript Libraries > npm
I get an empty view with
package.json not found
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 inside nbactions.xml
, I've gave it a display name of npm-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.