简体   繁体   中英

Maven Build Plugin doesn't include my own classes

I have the following (very) simple pom.xml:

<?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>ro.ace.ucv</groupId>
    <artifactId>message_generator</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <scala.major.version>2.10</scala.major.version>
        <scala.version>${scala.major.version}.5</scala.version>
        <spark.version>1.6.0</spark.version>
        <spark.streaming.version>1.6.0</spark.streaming.version>
        <spark.sql.version>1.6.0</spark.sql.version>
        <spark.version>1.6.0</spark.version>
        <junit.version>4.12</junit.version>
        <scalatest.version>2.1.3</scalatest.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>${spark.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.11</artifactId>
            <version>0.10.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.avro</groupId>
            <artifactId>avro</artifactId>
            <version>1.8.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.message.generator.MessageGeneratorMain</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

and the following (very) simple project structure:

\\message_generator\\src\\main\\scala\\com\\message\\generator\\MessageGeneratorMain.scala

When running mvn clean compile assembly:single

I get a jar with dependencies, but my own code (3 classes, including the Main one) is not included in the final jar.

You must include the Maven Scala plugin to catch the scala code in src/main/scala

<build>
    <plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
           <artifactId>maven-scala-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM