简体   繁体   English

如何通过Vaadin导入外部主题并将其与注释一起使用?

[英]How can I import external themes with Vaadin and use them with annotations?

Let's say I have two projects. 假设我有两个项目。 CompanyApp and CompanyVaadinThemes . CompanyAppCompanyVaadinThemes

CompanyApp is a normal Vaadin 7.7.3 app. CompanyApp是正常的Vaadin 7.7.3应用程序。 CompanyVaadinThemesis just a Vaadin 7.7.3 theme compiled into a jar. CompanyVaadinThemesis只是将Vaadin 7.7.3主题编译成一个jar。

CompanyVaadinThemes.jar CompanyVaadinThemes.jar

source/main/resources/VAADIN/themes/mytheme
    mytheme.scss
    styles.scss
    ...

CompanyApp.war CompanyApp.war

pom.xml
    ...
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-themes</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.company</groupId>
        <artifactId>company-vaadin-themes</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>


...

UI.java

    @SpringUI
    @Theme("mytheme")
    public class CompanyUI extends UI {

However, I can't seem to figure out how to make this work. 但是,我似乎无法弄清楚如何进行这项工作。 If I copy the actual code from the CompanyVaadinThemes.jar into the main CompanyApp, all is fine. 如果我将实际代码从CompanyVaadinThemes.jar复制到主CompanyApp,一切都很好。 I can use "mytheme", "valo", etc. 我可以使用“ mytheme”,“ valo”等

But I want to keep the actual theme in a separate project so that future projects can just simply add it as a dependency. 但是我想将实际主题保留在一个单独的项目中,以便将来的项目可以简单地将其添加为依赖项。

Here is the pom to CompanyVaadinThemes: 这是CompanyVaadinThemes的pom:

<?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>com.company</groupId>
    <artifactId>company-vaadin-themes</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <vaadin.version>7.7.3</vaadin.version>
        <vaadin.theme>mytheme</vaadin.theme>
        <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
    </properties>

    <repositories>
        <repository>
            <id>vaadin-addons</id>
            <url>http://maven.vaadin.com/vaadin-addons</url>
        </repository>
        <repository>
            <id>com-vaadin-prereleases</id>
            <url>https://maven.vaadin.com/vaadin-prereleases</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-server</artifactId>
            <version>${vaadin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-themes</artifactId>
            <version>${vaadin.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
            </plugin>

        </plugins>
    </build>
</project>

VAADIN folder in your theme should be in the root of your jar file: 主题中的VAADIN文件夹应位于jar文件的根目录中:

VAADIN/themes/mytheme
    mytheme.scss
    styles.scss

Custom themes are placed in the VAADIN/themes folder of the web application, in an Eclipse project under the WebContent folder or src/main/webapp in Maven projects. 自定义主题放置在Web应用程序的VAADIN / themes文件夹中,WebContent文件夹下的Eclipse项目或Maven项目中的src / main / webapp中。 This location is fixed. 此位置是固定的。 You need to have a theme folder for each theme you use in your application, although applications rarely need more than a single theme. 您需要为应用程序中使用的每个主题都拥有一个主题文件夹,尽管应用程序很少需要多个主题。 After you place them in folder it's easy to call them with @Theme("your_theme_goes_here") annotation. 将它们放置在文件夹中后,可以使用@Theme(“ your_theme_goes_here”)批注轻松调用它们。 Also make sure you are recompiling, simply Clean and Build to make changes work efficiently. 还请确保您正在重新编译,只需清除并构建即可使更改有效地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM