Problem: I'd like to specify the main class in a jar file that I am packaging using m2eclipse: [right-click] -> Run As -> Maven package. I'm still learning Maven and from what I've read, the straight-up way of accomplishing this task is to add a stanza to the pom.xml.
Here are examples I found when I was researched this issue:

My question is this: is it okay to manually edit the pom.xml file outside of Eclipse/m2eclipse using a text editor, or should I be doing this configuration using the m2ecplise GUI? There are several tabbed dialog boxes that seem like they might be likely candidates for this task, like "Plugins" and "Build". I looked through Sonatype's documentation and couldn't find any detailed instructions on how to accomplish what I need to do.

I'm a little hesitant to edit the pom.xml manually because I notice the "Effective POM" already has a lot of extra stuff in it, including the plugin definition that needs to have added to it:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
      <execution>
        <id>default-jar</id>
        <phase>package</phase>
        <goals>
          <goal>jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

If I understand correctly, the Effective POM needs to be changed so that the plugin is configured like this:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
      <execution>
        <id>default-jar</id>
        <phase>package</phase>
        <goals>
          <goal>jar</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
    <archive>
    <manifest>
         <mainClass>[name of main class]</mainClass>
         <packageName>[package name]</packageName>
    </manifest>
        <manifestEntries>
            <mode>development</mode>
            <url>${pom.url}</url>
    </manifestEntries>
    </archive>
    </configuration>
  </plugin>

Is this right? And if so, do I do this through m2eclipse or should I just copy all the extra Effective POM stuff and paste it into the actual pom.xml using a text editor?

Thanks to anyone who can shed some light.

UPDATE: I went ahead and manually edited the pom.xml file in a text editor. When I viewed Effective POM in m2eclipse it displayed everything that I put in (I assume). I built the jar and the main class was correctly set.

This seems like a hack to me though. Does anyone know if there's a way to do this configuration using m2eclipse itself? I checked the m2eclipse tabs and nothing seemed to have been updated as a result of my manual edits of pom.xml (other than the Effective POM tab).

有帮助吗?

解决方案

m2eclipse doesn't do everything for you, i.e. there isn't a pretty UI tab for handling everything.

My team is most comfortable with editing the POM manually, and using the other tabs for verification (like Effective POM view).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top