简体   繁体   English

Vaadin:如何在战争中加入META-INF /服务?

[英]Vaadin: How to add META-INF/services to the war?

I have a Vaadin 7 maven web project that has some annotations that create service definition on META-INF/services . 我有一个Vaadin 7 maven web项目,它有一些注释可以在META-INF/services上创建服务定义。

I added this to the pom so the annotations are processed: 我将其添加到pom中以便处理注释:

<!-- Run annotation processors on src/main/java sources -->
<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>3.3.1</version>
    <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
</plugin>

The files show within target/classes/META-INF/services but don't make it to the final war. 这些文件显示在target/classes/META-INF/services但不会进入最后的战争。

I tried adding the folder to the maven-war-plugin like this: 我尝试将文件夹添加到maven-war-plugin,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <packagingIncludes>target/classes/*</packagingIncludes>
    </configuration>
</plugin>

But then most of the Vaadin files don't make it into the war and it doesn't work. 但是大部分的Vaadin文件并没有进入战争,也没有用。 Any idea? 任何想法?

You can try this: 你可以试试这个:

<execution>
    <id>process</id>
    <phase>generate-sources</phase>
    <goals>
        <goal>process</goal>
    </goals>
    <configuration>
        <finalName>${projectId}</finalName>
        <outputDirectory>relative project directory</outputDirectory>
        <includes>
            <include>path</include>
        </includes>
    </configuration>
</execution>

Please see https://maven.apache.org/plugins/maven-war-plugin/usage.html 请参阅https://maven.apache.org/plugins/maven-war-plugin/usage.html

It looks like your META-INF folder is in src/main/resources directory. 看起来您的META-INF文件夹位于src/main/resources目录中。

Normally when creating a WAR you would create a directory src/main/webapp where you can have your WEB-INF , META-INF and other required folders. 通常在创建WAR您将创建一个目录src/main/webapp ,您可以在其中拥有WEB-INFMETA-INF和其他必需的文件夹。

 |-- src
 |   `-- main
 |       |-- java
 |       |   `-- com
 |       |       `-- example
 |       |           `-- projects
 |       |               `-- SampleAction.java
 |       |-- resources
 |       |   `-- images
 |       `-- webapp
 |           |-- META-INF
 |           |-- WEB-INF

Everything from your webapp folder will be copied over to the root dir in the WAR . 您的webapp文件夹中的所有内容都将复制到WAR的根目录。

The path to your webapp can also be configured using warSourceDirectory property 您还可以使用warSourceDirectory属性配置Web webapp程序的路径

For your scenario - generated sources 对于您的方案 - 生成的源

Obviously you don't want to keep your generated sources in your src/* folder and don't want to version it. 显然,您不希望将生成的源保留在src/*文件夹中,并且不希望对其进行版本化。

You can get around this by either adding an ignore filter to your version control metadata; 您可以通过向版本控制元数据添加忽略过滤器来解决此问题; or by creating a symlink; 或者通过创建符号链接; or using copy-resources as some previous answers said, but not recommended. 或使用copy-resources作为之前的一些答案说,但不推荐。

You can achieve this by adding a webResources configuration to copy the generated sources from target folder by 您可以通过添加webResources配置来从target文件夹复制生成的源来实现此target

Please see http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html 请参阅http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

<plugin> 
  <groupId>org.apache.maven.plugins</groupId> 
  <artifactId>maven-war-plugin</artifactId> 
  <configuration> 
    <webResources> 
      <resource> 
        <directory>${project.build.directory}/target/generated-sources</directory> 
        <targetPath>META-INF</targetPath> <!-- introduced in plugin v 2.1 -->
        <includes> 
          <include>*.class</include> 
        </includes> 
      </resource> 
    </webResources> 
  </configuration> 
</plugin> 

I ended up using the approach from this unrelated answer: Maven: include folder in resource folder in the war build . 我最终使用了这个无关答案的方法: Maven:在war build中的资源文件夹中包含文件夹

Here's what I ended up doing: 这是我最终做的事情:

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <webResources>
                        <resource>
                            <directory>target/classes/META-INF/services</directory>
                            <includes>
                                <include>*.*</include>
                            </includes>
                            <targetPath>META-INF/services</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

Basically added the services folder as a resource and placed it on the right place of the final war. 基本上将services文件夹添加为资源并将其放置在最终战争的正确位置。

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

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