让maven正常编译scala、java代码混合的工程

  • 编辑pomxml
  • 编译
  • 制作war包

编辑pom.xml

假设代码所在目录为:
src/main/java
src/main/scala
src/test/java
src/test/scala

加入如下编译指令

    <packaging>warpackaging>
    <properties>
        <maven.compiler.source>1.8maven.compiler.source>
        <maven.compiler.target>1.8maven.compiler.target>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <encoding>UTF-8encoding>
        <maven.test.skip>truemaven.test.skip>
    properties>

    <build>
        <finalName>${project.artifactId}finalName>
        <outputDirectory>target/classesoutputDirectory>
        <testOutputDirectory>target/test-classestestOutputDirectory>
        <pluginManagement>
        pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.mavengroupId>
                <artifactId>scala-maven-pluginartifactId>
                <version>3.2.2version>
                <executions>
                    <execution>
                        <id>scala-compile-firstid>
                        <phase>process-resourcesphase>
                        <goals>
                            <goal>add-sourcegoal>
                            <goal>compilegoal>
                        goals>
                    execution>
                    <execution>
                        <id>scala-test-compileid>
                        <phase>process-test-resourcesphase>
                        <goals>
                            <goal>testCompilegoal>
                        goals>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.5.1version>
                <executions>
                    <execution>
                        <phase>compilephase>
                        <goals>
                            <goal>compilegoal>
                        goals>
                    execution>
                executions>
            plugin>

            <plugin>
                <groupId>org.codehaus.mojogroupId>
                <artifactId>build-helper-maven-pluginartifactId>
                <version>3.0.0version>
                <executions>
                    <execution>
                        <id>add-sourceid>
                        <phase>generate-sourcesphase>
                        <goals>
                            <goal>add-sourcegoal>
                        goals>
                        <configuration>
                            <sources>
                                <source>src/main/scalasource>
                            sources>
                        configuration>
                    execution>
                    <execution>
                        <id>add-test-sourceid>
                        <phase>generate-sourcesphase>
                        <goals>
                            <goal>add-test-sourcegoal>
                        goals>
                        <configuration>
                            <sources>
                                <source>src/test/scalasource>
                            sources>
                        configuration>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-war-pluginartifactId>
                <version>2.6version>
                <configuration>
                    <warSourceDirectory>${project.basedir}/WebContentwarSourceDirectory>
                    <packagingExcludes>WEB-INF/lib/commons-logging*.jarpackagingExcludes>
                configuration>
            plugin>

        plugins>

    build>

编译

执行命令:mvn compile
输出的class在target目录

制作war包

执行命令:mvn package

你可能感兴趣的:(scala,scala,java,maven)