Manushi
Manushi

Reputation: 759

com.vaadin.flow.router.RouteNotFoundError - Couldn't find route for 'sw.js'

I have built a tiny web app in Vaadin 8 and migrated to Vaadin 14 MPR. The components are displaying but during the jetty:run I get exception as below

[qtp729679840-28] INFO com.vaadin.flow.router.RouteNotFoundError - Couldn't find route for 'sw.js' com.vaadin.flow.router.NotFoundException: Couldn't find route for 'sw.js'

I have added the dependencies as shown in the pom.xml. I am trying to add one or more components to a Vaadin 8 designer file, which had only two vertical layouts.

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>vaadin-8-to-14-mpr-1</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>vaadin-8-to-14-mpr-1</name>

<prerequisites>
    <maven>3</maven>
</prerequisites>

<properties>
    <vaadin.version>14.8.1</vaadin.version>
    <vaadin.plugin.version>14.8.1</vaadin.plugin.version>
    <vaadin.setup.version>8.14.3</vaadin.setup.version>
    <jetty.plugin.version>9.4.36.v20210114</jetty.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <!-- If there are no local customizations, this can also be "fetch" or "cdn" -->
    <vaadin.widgetset.mode>local</vaadin.widgetset.mode>
</properties>

<repositories>
    <repository>
        <id>vaadin-addons</id>
        <url>http://maven.vaadin.com/vaadin-addons</url>
    </repository>
    <repository>
        <id>osgeo</id>
        <name>OSGeo Release Repository</name>
        <url>https://repo.osgeo.org/repository/release/</url>
        <snapshots><enabled>false</enabled></snapshots>
        <releases><enabled>true</enabled></releases>
    </repository>
</repositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-server</artifactId>
        <version>${vaadin.setup.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.jsoup</groupId>
                <artifactId>jsoup</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.google.gwt</groupId>
                <artifactId>gwt-elemental</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!--        <dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-push</artifactId>
    <version>${vaadin.setup.version}</version>
  </dependency>
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-client-compiled</artifactId>
  </dependency>-->
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-themes</artifactId>
                <version>${vaadin.setup.version}</version>
    <!--    <version>8.13.3</version>-->
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-core</artifactId>
        <version>14.8.1</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>mpr-v8</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.25</version>
    </dependency>

    <dependency>
        <groupId>org.vaadin.addon</groupId>
        <artifactId>v-leaflet</artifactId>
        <version>2.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.locationtech.jts</groupId>
        <artifactId>jts-core</artifactId>
        <version>1.16.0</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geojson</artifactId>
        <version>14.5</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <!-- Exclude an unnecessary file generated by the GWT compiler. -->
                <packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>8.7.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>resources</goal>
                <!--        <goal>update-theme</goal>-->
                        <goal>update-widgetset</goal>
                        <goal>compile</goal>
                        <!-- Comment out compile-theme goal to use on-the-fly theme compilation -->
                    <!--    <goal>compile-theme</goal>-->
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.0.0</version>
            <!-- Clean up also any pre-compiled themes -->
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main/webapp/VAADIN/themes</directory>
                        <includes>
                            <include>**/styles.css</include>
                            <include>**/styles.scss.cache</include>
                        </includes>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>

        <plugin>
        <groupId>com.vaadin</groupId>
        <artifactId>flow-maven-plugin</artifactId>
        <version>2.7.6</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-frontend</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

        <!-- The Jetty plugin allows us to easily test the development build by
            running jetty:run on the command line. -->
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.plugin.version}</version>
            <configuration>
                <scanIntervalSeconds>2</scanIntervalSeconds>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <!-- Vaadin pre-release repositories -->
        <id>vaadin-prerelease</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>

        <repositories>
            <repository>
                <id>vaadin-prereleases</id>
                <url>http://maven.vaadin.com/vaadin-prereleases</url>
            </repository>
            <repository>
                <id>vaadin-snapshots</id>
                <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>vaadin-prereleases</id>
                <url>http://maven.vaadin.com/vaadin-prereleases</url>
            </pluginRepository>
            <pluginRepository>
                <id>vaadin-snapshots</id>
                <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

My Java UI Code

package org.example;

import com.vaadin.annotations.Theme;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;
import com.vaadin.mpr.core.HasLegacyComponents;
import com.vaadin.ui.Button;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextField;
import org.example.ui.MyUIPresenter;
import org.vaadin.addon.leaflet.LFeatureGroup;
import org.vaadin.addon.leaflet.LMap;
import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
import org.vaadin.addon.leaflet.LTileLayer;
import org.vaadin.addon.leaflet.LeafletLayer;


@Theme("mytheme")
@Route("")
public class MyUI extends Div implements HasLegacyComponents {

  private LTileLayer osmTiles = new LOpenStreetMapLayer();
  private MyUIPresenter myUIPresenter;
  LMap map = new LMap();
  private LFeatureGroup lfg = new LFeatureGroup();
  ;
  LeafletLayer leafletLayer;


  public MyUI() {

    myUIPresenter = new MyUIPresenter();
    final TextField mapText = new TextField();
    mapText.setCaption("Map component");
    map.addBaseLayer(osmTiles, "OSM");
    map.setCenter(51.18641111764806, 10.428327809551346);
    map.setZoomLevel(5);
  /*  myUIPresenter.addComponentToMapLayout(mapText, "left: 30px; top: 50px;");
    //  myUIPresenter.addComponentToMapLayout(map, "z-index: 0");*/
    myUIPresenter.addComponentToMapVerticalLayout(mapText);
    myUIPresenter.addComponentToMapVerticalLayout(map);
    final TextField name = new TextField();
    name.setCaption("Type your name here:");
    myUIPresenter.addComponentToUILayout1(name);
    Button button = new Button("Click Me");
    myUIPresenter.addComponentToUILayout1(button);
    button.addClickListener(e -> {
      Notification.show("Good " + name.getValue() + ". This works");
    });
    add(myUIPresenter.getView());
  }

}

Upvotes: 1

Views: 1669

Answers (1)

Manushi
Manushi

Reputation: 759

I got an answer from Vaadin Team. I did not add @PWA annotation.

Answer from Vaadin Team: There is possibly sw.js registered by a previous app you have used on the same computer. So probably unregistering service workers from browser settings will help, Browser registers service workers against the URL, so if you try out different apps locally, the registrations collide with localhost.

Solution: After adding the annotation, the exception disappeared.

Thank you, very much, Mr.Tatu for your help.

Upvotes: 3

Related Questions