maven本地安装在IDEA中创建maven项目

先下载maven安装包。
我下载的是apache-maven-3.6.1
解压后在本地添加环境变量。如下:

maven本地安装在IDEA中创建maven项目_第1张图片
maven本地安装在IDEA中创建maven项目_第2张图片
在cmd输入mvn -v查看是否生效。
maven本地安装在IDEA中创建maven项目_第3张图片
接下来创建Maven项目。如图所示:
maven本地安装在IDEA中创建maven项目_第4张图片
maven本地安装在IDEA中创建maven项目_第5张图片
maven本地安装在IDEA中创建maven项目_第6张图片
创建完项目,添加依赖和maven工程。如下:

maven本地安装在IDEA中创建maven项目_第7张图片
maven本地安装在IDEA中创建maven项目_第8张图片
其中settings.xml文件中修改如下:
maven本地安装在IDEA中创建maven项目_第9张图片
maven本地安装在IDEA中创建maven项目_第10张图片

在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>Spack_demo</groupId>
    <artifactId>Spack_demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
//以下是添加的信息
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_2.10</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-hive_2.10</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming_2.10</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming-kafka_2.10</artifactId>
            <version>1.5.1</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test</testSourceDirectory>

        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass></mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                    <includeProjectDependencies>true</includeProjectDependencies>
                    <includePluginDependencies>false</includePluginDependencies>
                    <classpathScope>compile</classpathScope>
                    <mainClass>cn.spark.study.core.WordCountCluster_5</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

        </plugins>

    </build>

</project>

添加完就可以下载包了,在右下角点击import Changes。如下:
maven本地安装在IDEA中创建maven项目_第11张图片
下载完了后,如果在src不能创建package,就进行如下操作
maven本地安装在IDEA中创建maven项目_第12张图片
这样就可以正常使用了。

你可能感兴趣的:(maven本地安装在IDEA中创建maven项目)