简体   繁体   English

同时使用Maven Jar插件和Spring引导maven插件

[英]Use Maven Jar plugin and Spring boot maven plugin simultaneously

I am trying to create jar for my spring boot server using spring boot maven plugin and my test automation framework jar from same project and pom file.我正在尝试使用 spring 引导 maven 插件和来自同一项目和 pom 文件的测试自动化框架 jar 为我的 spring 引导服务器创建 jar。 To read external resources I am trying to defined manifest entries in maven jar plugin but this is causing spring server to not find application.properties in its default locations when run as a linux service using /etc/init.d/my-jar start.要读取外部资源,我试图在 maven jar 插件中定义清单条目,但这导致 spring 服务器在使用 /etc/init.d/my-jar start 作为 linux 服务运行时无法在其默认位置找到 application.properties。

Here is snippet of my pom file这是我的 pom 文件的片段

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.5.3</version>
  <configuration>
    <descriptors>
      <descriptor>src/assembly/dep.xml</descriptor>
    </descriptors>
    <archive>
      <manifest>
        <mainClass>com.myorg.mainclass</mainClass>
      </manifest>
    </archive>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>springloaded</artifactId>
      <version>1.2.5.RELEASE</version>
    </dependency>
  </dependencies>

</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.2.2</version>
  <configuration>
    <finalName>${project.artifactId}-${project.version}-main-only</finalName>
    <archive>
      <manifest>
        <mainClass>com.myorg.mainclass</mainClass>
      </manifest>
      <manifestEntries>
        <Class-Path>./config/</Class-Path>
      </manifestEntries>
    </archive>
    <excludes>
      <exclude>**/application-test.properties</exclude>
    </excludes>
  </configuration>
  <executions>
    <execution>
      <phase>verify</phase>
      <goals>
        <goal>test-jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

I have tried changing phase of my maven assembly and jar plugin to verify but the problem still persists.我已经尝试更改我的 maven 程序集和 jar 插件的阶段来验证,但问题仍然存在。 Removing manifest entry seems to work but then my external resource files are not read.删除清单条目似乎有效,但我的外部资源文件未被读取。

To solve the problem I removed the manifest entries from maven jar plugin and then while running the test jar. I added the external resource directory path into classpath as follows:为了解决这个问题,我从 maven jar 插件中删除了清单条目,然后在运行测试 jar 时将外部资源目录路径添加到类路径中,如下所示:

java -classpath my/external/resource/directory/path -jar my-tests.jar

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

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