my maven project has the following structure:
- "base" module -- contains shared java files -- should contain shared javascript files
- module 1 -- use shared java files as maven dependency -- should use shared javascript files using ?
- module 2 -- use shared java files as maven dependency -- should use shared javascript files using ?
Currently, webpack seems to be the new thing in javascript packaging and npm seems to be a proper package manager. So i tried the following: - base modules creates a npm bundle (with npm pack) using webpack - modules 1 and 2 install this bundle manually using a relative path to the base module target folder where the npm package is
Why didn't i use npm publish? - Its not possible to update published npm packages, so every build would need to create a new version number - It would need an internet connection to build
Other options? - I thought about using the maven resources plugin, but this seems to be a lot of manual work included (file names, folders, etc.)
So what I'm asking for is: Do you share javascript code between maven modules within the same project? How do you achieve that? There has to be a better way to do that, or?
If you want to look at my project, take a look here:
Thanks in advance for your answers an ments!
my maven project has the following structure:
- "base" module -- contains shared java files -- should contain shared javascript files
- module 1 -- use shared java files as maven dependency -- should use shared javascript files using ?
- module 2 -- use shared java files as maven dependency -- should use shared javascript files using ?
Currently, webpack seems to be the new thing in javascript packaging and npm seems to be a proper package manager. So i tried the following: - base modules creates a npm bundle (with npm pack) using webpack - modules 1 and 2 install this bundle manually using a relative path to the base module target folder where the npm package is
Why didn't i use npm publish? - Its not possible to update published npm packages, so every build would need to create a new version number - It would need an internet connection to build
Other options? - I thought about using the maven resources plugin, but this seems to be a lot of manual work included (file names, folders, etc.)
So what I'm asking for is: Do you share javascript code between maven modules within the same project? How do you achieve that? There has to be a better way to do that, or?
If you want to look at my project, take a look here: https://github./stefanrinderle/softvis3d
Thanks in advance for your answers an ments!
Share Improve this question asked Jan 9, 2016 at 9:55 user984200user984200 3031 gold badge7 silver badges20 bronze badges 3- 1 I guess maven.apache/plugins/maven-remote-resources-plugin could be useful, but I can't give you full answer because your example is not enough simple to understood. Consider add very basic example (Maven multimodule, 3-4 projects, 1 JS file etc) and clear expectation – michaldo Commented Jan 11, 2016 at 22:15
- I guess OP has given you full access to his/her github repo... – Raja Anbazhagan Commented Jan 12, 2016 at 14:18
- @RajaAnbazhagan, I didn't want full access to repo. I suggested prepare example according to stackoverflow./help/mcve (anyway, issue is solved so case is closed) – michaldo Commented Jan 12, 2016 at 20:45
2 Answers
Reset to default 6 +50Basically to redistribute npm modules separately you should use npm publish
. During dev time, though, npm has nice feature npm link
, that links your local folder as global dependency and makes npm use it instead of downloading from repository. So, I've just added npm link
to your project and changed node installation directory so all submodules use the same node instance. This way you can develop your modules easily and publish whenever you're ready.
base/pom.xml:
<plugin>
<groupId>.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
...
<configuration>
...
<installDirectory>../node</installDirectory>
</configuration>
<executions>
<execution>
<id>npm link</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>link</arguments>
</configuration>
</execution>
</executions>
</plugin>
..module/pom.xml
<plugin>
<groupId>.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<installDirectory>../node</installDirectory>
</configuration>
<executions>
<execution>
<!-- link before install -->
<id>npm link softvis3d-viewer</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>link softvis3d-viewer</arguments>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
...
</executions>
</plugin>
..module/package.json
"devDependencies": {
...
"softvis3d-viewer": "0.0.4-SNAPSHOT"
},
NPM works if the Maven module supplies JavaScript that will undergo transpiling / minification / concatenation. If sharing of pre-piled modules is required, I successfully use web-fragment.xml (defined in Servlet 3.0 specs) and put my JavaScript etc. under META-INF/resources. Depending on your front end technology, you will need to use some approach relevant to code splitting, or web ponents.
In essence, client side will need to load and execute your library code before running anything that depends on it.
If you have a small(-ish) library with specific API you want to share between your Maven modules, and it is all part of the same eco-system, npm publish
and npm link
is a way to go. For bigger chunks of functionality, especially ones that have specific usage profiles (say, user profile editor or configuration page - not used every time), those can be dynamically loaded).
While nothing in it is new, this area (POMs, JARs, NPMs and JS/ES6 modules) seems to be in a search of the best approach and it will take some time to settle on a couple of robust techs. I don't know a clean, absolutely no band-aids, set of rules and settings to deal with it.