1

I want two assemblies to be built one using:

<mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>

and the other using:

<mainClass>com.jthink.songkong.cmdline.SongKong2</mainClass>

I understand I need to use profiles but so far my attempts have had no effect, and running mvn with the -P option doesnt make any differnce either whether I put in a real profilename or a made up has no effect. Its not clear quite how to do this so Ive just posted my original POM without my failed attempts, a full replacement POM would be helpful.

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.jthink</groupId>
    <artifactId>songkong</artifactId>
    <version>4.6</version>
    <repositories>
        <repository>
            <id>jaudiotagger-repository</id>
            <url>https://dl.bintray.com/ijabz/maven</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>net.jthink</groupId>
            <artifactId>jaudiotagger</artifactId>
            <version>2.2.6-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.com4j</groupId>
                    <artifactId>maven-com4j-plugin</artifactId>
                    <version>2.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.jvnet.com4j</groupId>
                <artifactId>maven-com4j-plugin</artifactId>
                <version>2.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <compilerVersion>1.8</compilerVersion>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>
                            <packageName>com.jthink.songkong</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>../lang/</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                    <archive>
                        <manifest>
                            <mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>
                            <packageName>com.jthink.songkong</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Update based on linked question

So Ive created two executions, each with a different value for MainClass and it has made no difference, still just creating the single songkong-4.6-jar-with-dependencies.jar with the first class file referenced in the Manfest.mf file.

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>make-assembly-1</id>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <archive>
                                <manifest>
                                    <mainClass>com.jthink.songkong.cmdline.SongKong</mainClass>
                                    <packageName>com.jthink.songkong</packageName>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>make-assembly-2</id>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies2</descriptorRef>
                            </descriptorRefs>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <archive>
                                <manifest>
                                    <mainClass>com.jthink.songkong.cmdline.SongKong2</mainClass>
                                    <packageName>com.jthink.songkong</packageName>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • No profiles are not for this use-case, see the linked question or http://stackoverflow.com/questions/7239786/how-to-invoke-the-same-maven-build-twice-in-one-call. Notice that you'll need to use a custom classifier here, otherwise they'll overwrite each other. – Tunaki Feb 17 '17 at 13:22
  • @Tunaki Well, the accepted answer there mentions profiles at the end, as well. ;) – Gerold Broser Feb 17 '17 at 13:36
  • @Tunaki And the [question that led here](http://stackoverflow.com/q/42285827/1744774) was about _one_ `.java` source file with alternating content. – Gerold Broser Feb 17 '17 at 13:45
  • @Tunaki overwriting may be okay if I could run mvn once create build and move, and then run a second time for the otrher scenario but I cant get profiles to do anything, i.e manifest is always SongKong rather than SongKong2 – Paul Taylor Feb 17 '17 at 14:48
  • @Tunaki Ive tried to get it working based on linked question but made no difference, the linked question is similar but not the same so please reopen and tell me what Im doing wrong. – Paul Taylor Feb 20 '17 at 09:44
  • I told what you were doing wrong [in my first comment](http://stackoverflow.com/questions/42299040/how-do-i-make-this-maven-pom-have-two-profiles-only-difference-being-in-mainclas#comment71752523_42299040), to which you replied that overwriting was not an issue.... It is an issue, and you just need to use different [classifier](http://maven.apache.org/components/plugins-archives/maven-assembly-plugin-2.6/single-mojo.html#classifier) for the two executions. – Tunaki Feb 20 '17 at 09:53
  • Note that with 3.0.0, you'll need to replicate the [`jar-with-dependencies`](http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies) descriptor format in two different `assembly.xml` that have different `` (because `classifier` was removed and the assembly id is used instead). – Tunaki Feb 20 '17 at 09:53
  • @Tunaki as the linked question doesnt mention classifiers why have you closed as a duplicate. As it is I am using maven 3 my assembly.xml has no mention of a descriptor format and assemblys are not mentioned in the linked question either so really this question should be reopened. Im a Java software developer not a Maven expert and answer to this question would be of benefit to the StackOverflow community – Paul Taylor Feb 20 '17 at 09:59
  • Ok you're going too fast here, so I'll walk away. But first, 3.0.0 is not the Maven version, but the Assembly Plugin version (and you're using 2.3 apparently). Second, [descriptor format](http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html) is documented and what you are using with the `assembly.xml` configured in your POM. Look at those questions about the same: [here](http://stackoverflow.com/questions/15798936), [here](http://stackoverflow.com/questions/8726884) and [here](http://stackoverflow.com/questions/12727612) (that are better dupes, I'll see about changing that). – Tunaki Feb 20 '17 at 10:14
  • @Tunaki Unfortunately although the concept of maven is great the documentation is poor it explains everything without explaining anything I was hopeful that stackoverflow could answer the question instead of just referring me to documentation and other questions that are different. Ive looked at al these new links and none have both maven-jar-plugi and a maven-assembly-plugin and ti think that might be what causes nothing to work. Myavbe I will just have to create two seperate pom files as a heavy headed kludge. – Paul Taylor Feb 20 '17 at 12:21
  • That's because you don't need the maven-jar-plugin, nor do you need the `true`. You just need what is mentioned in the three linked questions above. – Tunaki Feb 20 '17 at 12:23
  • @Tunaki If I have to take bits from three different questions then it isnt really a duplicate is it ? I do need both build-jar and build-with-dependencies because I have to package up differently for different oses (i.e installer for Windows, .dmg file for OSX ectera). not possible to work with them both inside. – Paul Taylor Feb 20 '17 at 13:04
  • Sorry, I meant that the 3 questions lead the same solution, [like this one](http://stackoverflow.com/a/15799254/1743880) (and they are duplicates). It contains the full plugin configuration that solves the issue. You didn't mention a build for different OS though, that sounds like a new question. – Tunaki Feb 20 '17 at 13:13
  • @Tunaki they are all subtley different and none seem to work for me. Building for different oses is irrelevant to this question except for the point I need both plugins, all I need is help modifying my pom so it can build two different versions with the different mainClass. If it so simple it would be helpful if somebody would just post an answer with my modified pom file, job done. – Paul Taylor Feb 20 '17 at 13:17
  • I fact I already posted an attempted solution based on executions, its not clear to me why it doestn work – Paul Taylor Feb 20 '17 at 13:20
  • @Tunaki are you going to reopen this it clearly is not 'an exact duplicate' of anything. – Paul Taylor Feb 20 '17 at 15:24
  • You win, I give up. – Paul Taylor Feb 20 '17 at 15:45

0 Answers0