在maven中更改pom包装时无法找到或加载主类

时间:2015-08-28 07:19:52

标签: java maven

所以我想在我的项目中添加几个模块。但是当我尝试添加新模块时,我的信息是“项目必须具有POM的打包类型”。当我将其更改为POM时,我有错误:“无法找到或加载主类pl.marek.countriesmapper.CountriesDirectoryMake”。

这是我的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>pl.marek</groupId>
    <artifactId>countries-mapper</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>CountriesMapper</name>
    <packaging>pom</packaging>    <----- Here when I have jar is all ok, when POM - error.

    <properties>
        <version.jacoco>0.7.5.201505241946</version.jacoco>
    </properties>

    <repositories>
        <repository>
            <id>codehaus</id>
            <url>http://repository.codehaus.org/org/codehaus</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
              <artifactId>jaxb-runtime</artifactId>
            <version>2.2.10-b140310.1920</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.3</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>1.5.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
        </dependency>       
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>appassembler-maven-plugin</artifactId>
                <groupId>org.codehaus.mojo</groupId>
                <version>1.7</version>
                <configuration>
                    <programs>
                        <program>
                            <mainClass>pl.marek.countriesmapper.CountriesDirectoryMake</mainClass>
                            <name>CountriesDirectoryMake</name>
                        </program>
                    </programs>   
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>pl.marek.countriesmapper.CountriesDirectoryMake</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${version.jacoco}</version>
                <configuration>
                    <skip>${maven.test.skip}</skip>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <!--make sure it runs AFTER integration tests -->
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

@edit

现在我创建了一个名为mapper的新POM Maven项目。新项目的POM如下所示:

<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>pl.marek</groupId>
  <artifactId>mapper</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>Mapper</name>
  <modules>
      <module>countries-maper</module>
  </modules>
</project>

在国家的pom.xml中,我改变了开始。现在它看起来像这样:

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>pl.marek</groupId>
    <artifactId>mapper</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>countries-mapper</artifactId>
<name>CountriesMapper</name>
<packaging>jar</packaging>

现在我有错误:

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]  
[ERROR]   The project pl.marek:countries-mapper:0.0.1-SNAPSHOT (/home/mateusz/Dokumenty/GIT/Countries/countries-maper/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not find artifact pl.marek:mapper:pom:0.0.1-SNAPSHOT in codehaus (http://repository.codehaus.org/org/codehaus) and 'parent.relativePath' points at wrong local POM @ line 4, column 10 -> [Help 2]

1 个答案:

答案 0 :(得分:1)

除了评论中提到的命名问题之外,您似乎还尝试在构建父模块之前构建子模块(countries-mapper)。

你应该从root(父pom存在的地方)运行mvn命令,并定义&#34; relativePath&#34; country-mapper的父定义中的标记。