3

I have a Web application and I'm using Maven. I do not have Spring MVC implemented in the project.

The project has a REST controller that is implemented and that is working just fine. I need to integrate a Google Dart into the application.

I'm using this dart-maven-plugin and I have the Dart code under "src/main/dart". Right now I have thrown the Dart tutorial code (pirate badge) and I'm trying to get that to work.

These are the files under src/main/dart

  • piratebadge.css
  • piratebadge.dart
  • piratebadge.html
  • piratebadge.json
  • pubspec.yaml

I would like to be able to deploy the project .war file into Tomcat and be able to get to localhost:8080/testapplication/piratebadge.html

Do I need to add this html file into my web.xml?

Here is the web.xml for reference

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <display-name>TestProject</display-name>

    <servlet>
        <servlet-name>controller</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>test.controller</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>controller</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>
Envin
  • 1,463
  • 8
  • 32
  • 69

1 Answers1

1

It's a long time since I worked with Java/Maven.

Basically you can develop your Dart application in any directory. You just generate the deployables with pub build and treat the output (generated in build/web) like any static content in your Java/Maven project.

It's a bit more complicated during development. If you can set the cross origin header in your server application you can connect to the Java REST server. You just have to maintain two configurations where you connect back to the server where the Dart app was loaded in production with a relative URL but in development you have to use an absolute URL.

For this you could use something like Dart: How to use different settings in debug and production mode?

You could also place you Dart source package directory inside your Java project and treat it like static content. But the paths still differ because development is in yourpackage/web and the build output is generated in yourpackage/build/web.

When the Dart application is served from your Java application you have to use a specific Launch configuration to be able to debug. Some more information here: Dart best practices for develop and production

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567