Packing javascript files in war?

I am developing a servlet-based Java project that should be packaged like war using Maven. Is there a way to include JavaScript (JS) files with this project (they must be available at some URL when the project is uploaded to Tomcat Server).

I looked around, but did not find any working solutions.

+5
source share
3 answers

Perhaps the best solution is to stick to the Maven agreement, which states that the root directory of your web application is src/main/webapp.

, Javascript src/main/webapp/javascript ( src/main/webapp/js), .

Maven WAR (. ) . :

 |-- pom.xml
 `-- src
     `-- main
         |-- java
         |   `-- com
         |       `-- example
         |           `-- projects
         |               `-- SampleAction.java
         |-- resources
         |   `-- images
         |       `-- sampleimage.jpg
         `-- webapp
             |-- WEB-INF
             |   `-- web.xml
             |-- index.jsp
             `-- jsp
                 `-- websource.jsp

, webapp/xxx, jsp .

cuh, Maven WAR, .

+12

maven-war-plugin :

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-war-plugin</artifactId>
       <version>2.0.2</version>
       <configuration>
           <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
           <webResources>
                <resource>
                    <directory>your/path/to/js</directory>
                    <targetPath>js</targetPath>
                </resource>
           </webResources>
       </configuration>
</plugin>

.

. , js classes.

+3

src/main/webapp. , , maven-archetype-webapp .

My current application has them under src / main / webapp / javascript and accesses them in JSP, for example:

<script type="text/javascript" src="javascript/jquery-1.4.2.min.js"></script>

(for jsp files in src / main / webapp, which are)

+1
source

All Articles