mojohaus / appassembler

https://www.mojohaus.org/appassembler/
MIT License
93 stars 49 forks source link

Allow for a completely flat appassembler output #105

Open tonyganchev opened 4 years ago

tonyganchev commented 4 years ago

Our product today consists of just a single executable jar-with-dependencies. We want to have appassembler generate a startup batch and shell script but we cannot afford for backward compatibility reasons to follow the standard appassembler directory layout. What we need is a simple flat structure containing both the jar and the startup scripts.

I tried to make such a layout work with appassembler to no avail. The generated batch script always looks for the parent directory of the script and then looks for a nested directory $repositoryName}.

Are we missing something?

We've been testing with 1.10 and 2.1.0 versions of appassembler.

Our pom.xml:

<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/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>com.example.the</groupId>
   <artifactId>app</artifactId>

   <properties>
      <main.class>com.example.path.to.the.App</main.class>
      <product.name>the-app</product.name>
      <repo.name>.</repo.name>
   </properties>

   <dependencies>
      ...
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
               <archive>
                  <manifest>
                     <mainClass>${main.class}</mainClass>
                  </manifest>
               </archive>
               <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
               </descriptorRefs>
               <finalName>${product.name}</finalName>
               <outputDirectory>${project.build.directory}/${repo.name}</outputDirectory>
            </configuration>
            <executions>
               <execution>
                  <id>assembly</id>
                  <phase>package</phase>
                  <goals>
                     <goal>single</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
               <mainClass>${main.class}</mainClass>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <configuration>
               <repositoryName>${repo.name}</repositoryName>
               <binFolder>.</binFolder>
               <repositoryLayout>flat</repositoryLayout>
               <assembleDirectory>${project.build.directory}</assembleDirectory>
               <binFileExtensions>
                  <unix>.sh</unix>
               </binFileExtensions>
               <programs>
                  <program>
                     <id>${product.name}</id>
                     <mainClass>${main.class}</mainClass>
                  </program>
               </programs><includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
               <generateRepository>false</generateRepository>
               <useWildcardClassPath>true</useWildcardClassPath>
            </configuration>
            <executions>
               <execution>
                  <id>assemble</id>
                  <phase>package</phase>
                  <goals>
                     <goal>assemble</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>
giflw commented 2 years ago

You can try use custom scripts. Just look at scripts used by appassembler, copy them to your project and customize.

You can point to those new script in configuration session:

<unixScriptTemplate>${basedir}/src/main/appassembler/unixBinTemplate.sh</unixScriptTemplate>
<windowsScriptTemplate>${basedir}/src/main/appassembler/windowsBinTemplate.bat</windowsScriptTemplate>