we would like to improve build configuration/integration of Java + JavaScript projects.

  • back-end : Java app, Spring framework, REST API + maven as build tool
  • front-end : HTML + CSS + JavaScript, (based on ng-boilerplate project template - it separates nicely all modules,services,directives,shared assets) and it's using few JavaScript tools like npm, Bower, Karma + Grunt

Workspace configuration is pretty simple - each project in separate directory :

    /workspace
     /JavaBackend
     /JsFrontend 

Problem is that developers are dealing with “Origin null is not allowed by Access-Control-Allow-Origin" messages in browsers as they run AJAX queries from front-end (from file://..../JSApp/build/index.hml) and Java App server is on localhost:8080. We could switch browser security off or modify headers to allow cross origin requests but we think it's not good way how to achieve that.

We don't want to have JS resources inside of Java project in /src/main/webapps/ as in production environment apps will be deployed on different machines and each app has it's own build server.

Do you have experience with similar project configuration ? What would you recommend to us ?

Meanwhile we will experiment with Tomcat 7 to check if it can e.g. serve external static resources (js stuff) out of context of java app

share|improve this question
    
I may prefer you start watching these tutorials that suits you requirements i guess=> youtube.com/… – webyildirim Dec 5 '14 at 9:30

For development purposes, I would let Tomcat include the front-end folder in the server.xml by means of a <Context> tag. The folder can be arbitrary and even in another repository (e.g. /GitRepos/ApplicationGui/app).

...
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">    
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
        <Context docBase="/workspace/JsFrontend" path="/"/>
        <Context docBase="FlexibleOrders" path="/FlexibleOrders" reloadable="true" source="org.eclipse.jst.j2ee.server:FlexibleOrders"/>
      </Host>
    </Engine>
  </Service>
</Server>

In production, I would recommend to make a Maven artefact out of the front-end. It can be then included via dependency in the backend like this:

<dependency>
    <groupId>org.enterprise</groupId>
    <artifactId>application-gui</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency> 

See this blog for a complete configuration for production:

http://wiki.switajski.de/2016/01/24/how-to-create-maven-artifact-with-static-web-resources.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.