How To: Maven Project for Creating JavaScript in Eclipse

How to configure my pom so that the folder works as a javascript build path?

I would like developers to import the project into eclipse and automatically have a JavaScript root folder in the eclipse build path to work with autocomplete and other JavaScript support.

+4
source share
2 answers

Here is what I am doing, and everything seems to be in order. I am using Eclipse Juno SR2 (Java EE for web developers) and Maven 3.0.5, right now. (I'm not an expert in either Eclipse or Maven, so I'm sure there is a more elegant way to do this. Please let me know!)

We want to have a project structure, as shown below, in accordance with the Maven conventions:

- src +-- main +-- java +-- js +-- webapp +-- WEB-INF +-- test +-- java +-- js 

And then we want the web application to be deployed with a structure like:

 - / +-- js +-- WEB-INF +-- classes 

The key part of Maven pom.xml is in the maven-war plugin, which copies the src / main / js files:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <archiveClasses>true</archiveClasses> <webResources> <!-- in order to interpolate version from pom into appengine-web.xml --> <resource> <directory>${basedir}/src/main/webapp/WEB-INF</directory> <filtering>true</filtering> <targetPath>WEB-INF</targetPath> </resource> <resource> <directory>${basedir}/src/main/js</directory> <filtering>true</filtering> <targetPath>js</targetPath> </resource> </webResources> </configuration> </plugin> 

(I'm using the Google App Engine for my projects right now, so the appengine-maven-plugin copies in my java code and other resources.) With this, you can use Maven to create your project. There are other Maven javascript plugins for testing and dependencies, etc., but I believe that this is the main functionality.

There are a few things on the Eclipse side:

  • Ensure that the use of the JavaScript Project Facet feature is enabled.
  • Under Project Properties -> JavaScript -> Include Path -> Source Tab, click "Add Folder" and select "src / main / js". Then you can delete all the default paths.
  • In the section "Project Properties" β†’ "Deploying the assembly" add the folder / src / main / js and set the deployment path accordingly (from my structure above, I want my javascript to go to "/ js".

I can manage my java dependencies and deploy AppEngine from Maven, or code and debug from Eclipse (after some fidingling around ), and it all seems to work. I would like to combine my js interface tests with Maven (possibly using the javascript-maven-plugin ), but this is another day's task.

+5
source

Javascript is an interpreted language, you do not need to create or compile it.

0
source

Source: https://habr.com/ru/post/1339081/


All Articles