Domanda

I want to be able to use the maven-assembly-plugin to produce a different result, depending on the maven call? To be more precise: I want to switch between the mainClass.

What's the best way to do this? Can I create two different goals to get this done? Or can I use a parameter along with the call assembly:single?

I thought of something like the following, but don't know how to execute selectively.

   <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>my.stuff.Main1</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>-main1</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>

    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>my.stuff.Main2</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>-main2</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
È stato utile?

Soluzione

Maybe this

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>${mainClass}</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>${assemblyRef}</descriptorRef>
    </descriptorRefs>
  </configuration>
</plugin>

and invoke maven with parameters -DmainClass=my.stuff.Main1 -DassemblyRef=-main1

For making this easier to use, create profile

<profiles>
    <profile>
      <id>main1</id>
      <properties>
        <mainClass>my.stuff.Main1</mainClass>
        <assemblyRef>-main1</assemblyRef>
      </properties>
    </profile>
    <profile>
      <id>main2</id>
      <properties>
        <mainClass>my.stuff.Main2</mainClass>
        <assemblyRef>-main2</assemblyRef>
      </properties>
    </profile>
</profiles>

and invoke maven with parameter -Pmain1.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top