java - 如何使用 Maven 打包 switchyard 应用程序

标签 java maven switchyard

如何使用 Maven 将开关站应用程序打包到我的另一个项目中?目前我正在尝试按照此处的说明进行操作 official dock .

但是没有结果,在启动应用程序时我在日志文件中看到了

Caused by: java.lang.NoClassDefFoundError: com/aspiderngi/common/switchyard/InventoryRequest
Caused by: java.lang.ClassNotFoundException: com.aspiderngi.common.switchyard.InventoryRequest from...

有没有可能实现呢?

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.switchyard</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <name>com.example.switchyard:sy-example</name>
    <artifactId>sy-example</artifactId>
    <properties>
        <switchyard.version>2.0.0.Final</switchyard.version>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    <packaging>war</packaging>

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

        <dependency>
            <groupId>com.aspiderngi</groupId>
            <artifactId>artifacts-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-camel</artifactId>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-camel-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-resteasy</artifactId>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-transform</artifactId>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-validate</artifactId>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-test-mixin-cdi</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-bean</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.switchyard</groupId>
                <artifactId>switchyard-plugin</artifactId>
                <version>${switchyard.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scannerClassNames>
                        <param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
                    </scannerClassNames>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <packagingExcludes>
                        WEB-INF/lib/*.jar,
                        WEB-INF/classes/META-INF/switchyard.xml
                    </packagingExcludes>
                    <webResources>
                        <resource>
                            <directory>target/classes/META-INF</directory>
                            <targetPath>WEB-INF</targetPath>
                            <includes>
                                <include>switchyard.xml</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

最佳答案

您可以使用 Maven Shade 插件: https://maven.apache.org/plugins/maven-shade-plugin/

例子:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <shadedClassifierName>jackofall</shadedClassifierName> <!--     Any name that makes sense -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

关于java - 如何使用 Maven 打包 switchyard 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31805993/

相关文章:

java - 在 Tomcat 上部署 Spring Boot + WebSocket + Stomp

java - 通过名称创建内部静态类实例

maven-2 - 使用 Maven 和 OSGi 快速周转

maven - 添加本地外部 jar - 不应指向项目目录中的文件

java - Camel 文件使用者在使用目录中的大量文件时表现极其缓慢

java - 找不到元素 'persistence' 的声明

java - 在运行时动态选择一个类

java - maven tomcat7部署报错403

Java 8 闭包和类型识别