代码之家  ›  专栏  ›  技术社区  ›  watery

如何配置在eclipsests中运行的springboot应用程序

  •  0
  • watery  · 技术社区  · 5 年前

    我有一个在STS中开发的springboot应用程序,它通过sapjava连接器连接到SAP。该连接器位于一个jar中,其规则禁止重命名或重新打包归档文件。

    由于应用程序必须在多个平台上运行,因此我在本地重新打包了SAP JCO JAR,其形式如下:

    connectors-project
    |   pom.xml
    |       
    +---sap-jco-api
    |       pom.xml
    |       sapjco3.jar
    |
    +---sap-jco-linux-x86_64
    |   |   pom.xml
    |   |       
    |   \---src
    |       \---main
    |           \---resources
    |                   libsapjco3.so
    |                   Readme.txt
    |                   sapjco3.jar
    |                   sapjcomanifest.mf
    |               
    \---sap-jco-nt-amd64
        |   pom.xml
        |       
        \---src
            \---main
                \---resources
                        Readme.txt
                        sapjco3.dll
                        sapjco3.jar
                        sapjco3.pdb
                        sapjcomanifest.mf
    

    这个 sap-jco-api 模块用于编译,其他模块用于执行。在每个项目的基础上处理适当的打包,配置 maven-dependency-plugin 每次插入。

    <?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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <packaging>...</packaging>
        <version>...</version>
    
        <name>...</name>
        <description>...</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.0.RELEASE</version>
        </parent>
    
      <properties />
    
        <build>
    
            <plugins>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifestEntries>
                                <Class-Path>sap-jco/sapjco3.jar</Class-Path>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <mainClass>...</mainClass>
                        <excludeGroupIds>com.sap</excludeGroupIds>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                      <execution>
                        <id>unpack-dependencies-package</id>
                        <phase>package</phase>
                        <goals>
                          <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeTransitive>true</excludeTransitive>
                            <includeGroupIds>com.sap</includeGroupIds>
                            <excludeArtifactIds>sap-jco-api</excludeArtifactIds>
                            <excludes>META-INF/**</excludes>
                          <outputDirectory>${project.build.directory}/sap-jco</outputDirectory>
                        </configuration>
                      </execution>
                    </executions>
                </plugin>
    
            </plugins>
    
        </build>
    
        <dependencies>
    
            <!-- Spring Boot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>...</artifactId>
            </dependency>
    
            <!-- SAP JCO connector -->
            <dependency>
                <groupId>com.sap</groupId>
                <artifactId>sap-jco-api</artifactId>
                <version>3.0.18</version> 
                <scope>provided</scope>
                <optional>true</optional>
            </dependency>
    
            <dependency>
                <groupId>com.sap</groupId>
                <artifactId>sap-jco-nt-amd64</artifactId>
                <version>3.0.18</version>
                <scope>provided</scope>
            </dependency>
    
            <!--  other -->
            <dependency>...</dependency>
    
        </dependencies>
    
    </project>
    

    包装时间 spring-boot-maven-plugin 将平台特定的文件复制到最终jar可见的子目录中 MANIFEST Class-Path 进入。

    这是Maven为POM创建的目标文件夹:

    application-project
    |   
    \---target
        |   application.jar
        |   
        \---sap-jco
                Readme.txt
                sapjco3.dll
                sapjco3.jar
                sapjco3.pdb
                sapjcomanifest.mf
    

    java -jar target\application.jar .

    右键单击 -> 运行方式 -> Spring Boot应用程序,项目似乎是以默认方式打包的—因此打包了SAP jar—并且执行中断:

    JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive [...]. It is not allowed to rename or repackage the original archive "sapjco3.jar".
    

    spring-boot:run

    这阻碍了我从IDE内部调试应用程序,而且我还被迫从命令行手动打包并运行它,从而减慢了开发速度。

    我能做什么?

    0 回复  |  直到 4 年前
    推荐文章