当前位置: 首页 > 面试题库 >

使用Maven构建完整的应用程序文件夹

寿翰飞
2023-03-14
问题内容

在将大多数Java独立应用程序部署到生产环境后,它们最终都位于一个类似这样的文件夹中。

myapp  
|->lib (here lay all dependencies)  
|->config (here lay all the config-files) 
|->myapp.bat  
|->myapp.sh

我想知道Maven中是否有任何东西可以为我构建该结构并将其放在tar.gz中。


问题答案:

这种部署目录结构非常流行,并已被apache maven和ant等许多出色的应用程序采用。

是的,我们可以通过在maven软件包阶段使用maven-assembly-plugin来实现。

示例pom.xml:

  <!-- Pack executable jar, dependencies and other resource into tar.gz -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-5</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals><goal>attached</goal></goals>
      </execution>
    </executions>
    <configuration>
      <descriptors>
        <descriptor>src/main/assembly/binary-deployment.xml</descriptor>
      </descriptors>
    </configuration>
  </plugin>

样本binary-deployment.xml:

<!--
  release package directory structure:
    *.tar.gz
      conf
        *.xml
        *.properties
      lib
        application jar
        third party jar dependencies
      run.sh
      run.bat
-->
<assembly>
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <includeBaseDirectory>true</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>src/main/java</directory>
      <outputDirectory>conf</outputDirectory>
      <includes>
        <include>*.xml</include>
        <include>*.properties</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>src/main/bin</directory>
      <outputDirectory></outputDirectory>
      <filtered>true</filtered>
      <fileMode>755</fileMode>
    </fileSet>
    <fileSet>
      <directory>src/main/doc</directory>
      <outputDirectory>doc</outputDirectory>
      <filtered>true</filtered>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>false</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>


 类似资料:
  • 在SpringBoot项目中,谁使用maven。找不到类 我绒球的一部分 项目结构 当我启动应用程序时,我得到了这个错误 错误:无法找到或加载主类com.acme.pay.ms.BillingServiceApplication导致:java.lang.ClassNotFoundExc0019:com.acme.pay.ms.BillingServiceApplication命令执行失败。 无法执

  • 问题内容: 我有一个使用Maven 2构建的桌面Java应用程序(但是如果有帮助的话,我可以升级到Maven 3),并且具有许多开源依赖项。我现在正尝试将其打包为独立版本,以使最终用户可以使用它,而无需安装maven或其他任何工具。 我已经成功地使用maven-assembly- plugin构建了一个包含所有依赖项的jar,但这并不是我真正想要的,因为使用LGPL库时,您是要重新分发要用作单独j

  • 我是JavaFX新手。我使用Maven创建了一个Hello World项目。当我在Eclipse中运行时,它工作得很好。 当我试图使用build.fxbuild构建应用程序时,我得到了这个错误。

  • 一个普通的应用程序由以下文件组成: 二进制文件 这个安装在 /usr/bin。 一个桌面文件 这个桌面文件向shell提供关于这个程序的重要信息,例如名称、图标、D-Bus名称,启动的命令行。安装在 /usr/share/applications. 一个图标 这个图标安装在 /usr/share/icons/hicolor/48x48/apps, 无论当前背景是什么系统都会到这里查找图标。 一个设

  • 问题内容: 如何使用Maven创建桌面(独立/ Swing)应用程序? 我正在使用Eclipse 3.6。 问题答案: 创建一个Maven项目,如下所示: 将以下条目添加到您的pom文件中: 将项目作为Maven项目导入到Eclipse,然后作为Java应用程序运行。