27

I noticed that there are a few Maven plugins for Eclipse that support JavaScript development. The problem with using these is that I cannot find any JavaScript artifacts in Maven Central Repository. Specifically, I was looking for JQuery.

Is there a dedicated Maven repository for JavaScript?

Thanks

David Roussel
  • 5,328
  • 1
  • 24
  • 33
Joe Wood
  • 1,135
  • 1
  • 12
  • 24

4 Answers4

11

Try webjars. http://www.webjars.org/

It has all the major libraries, plus it's in github, so you can fork your own versions if you really need to.

It should work well with a servlet 3 spec container with meta data scanning. But I use https://github.com/bazaarvoice/dropwizard-webjars-resource/ to serve it explicitly, since I'm using JAX-RS (using Jersey).

David Roussel
  • 5,328
  • 1
  • 24
  • 33
6

If your question is about repository of javascript, you can have a look at CDNs:

However, please be mindful that they do not provide a local javascript (like how Maven retrieve and store jars), thus Internet connection is necessary and there will be a network overhead.

And more, they do not manage dependencies of javascript. Dependency management of javascript is a much bigger issue in itself.

Hope I have answered your question.

wyz
  • 711
  • 3
  • 14
2

I have been working on and off in my spare time on a better story for Maven and JavaScript development. You can see the results of my efforts at jszip.org

Personally speaking I think there are only a few issues left to resolve:

  • How to handle LESS and SASS stylesheets in dependencies

  • Tidy up the code to make it more extensible

  • Better documentation.

As part of the effort, I do repackage JavaScript libraries as simple .zip files, you can see a complete list on central and you will note that jQuery is one of them, though I probably have to pick up the 1.9.x releases when I next get a window of opertunity

Because I am packaging these as plain simple .zip files you don't have to use the rest of the jszip toolchain, though obviously I think it superior to just unpacking the .zip as part of your build with, e.g. dependency:unpack-dependencies

Here is an example of how to add a jszip module using its tooling:

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.jszip.redist</groupId>
      <artifactId>jquery</artifactId>
      <version>1.8.3</version>
      <type>jszip</type>
    </dependency>
    ...
  </dependencies>

  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.jszip.maven</groupId>
        <artifactId>jszip-maven-plugin</artifactId>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>unpack</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>

  <!-- this next part assumes you want to minify all javascript for releases 
       and that your release profile used by the maven release plugin is called
       'release' (i.e. the default) -->
  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jszip.maven</groupId>
            <artifactId>jszip-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>optimize</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
Stephen Connolly
  • 13,197
  • 5
  • 34
  • 60
1

Maven is more popular for java than javascript, so you will only find a limited number of javascript libraries on the maven central repo. JQuery is quite popular though, and several packages for it exist on maven central as you can see here.

For other javascript libraries, you can try to get maven to use npm, which is a popular package management system for Node.js. There is a plugin that will allow you to download npm modules in your maven build. Here is the jquery npm package.

If that fails, you can always package the javascript libraries you need and upload them to maven central repo yourself.

sbridges
  • 24,059
  • 3
  • 60
  • 70