Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Intelij中为Maven项目创建运行配置?_Java_Maven_Intellij Idea_Jar - Fatal编程技术网

Java 在Intelij中为Maven项目创建运行配置?

Java 在Intelij中为Maven项目创建运行配置?,java,maven,intellij-idea,jar,Java,Maven,Intellij Idea,Jar,我有一个简单的标准Maven项目,我使用Intelij创建了这个项目 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.ap

我有一个简单的标准
Maven
项目,我使用
Intelij
创建了这个项目

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>org.example</groupId>
    <artifactId>MavenExample</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.15.Final</version>
        </dependency>

    </dependencies>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.rs.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
public class App {

    public static void main(String[] args) {

        System.out.println("Hello all!");
    }
}
目前,我首先运行此项目:

mvn clean install
然后导航到目标目录并运行:

java -jar MavenExample-1.0-SNAPSHOT.jar

如何在
intelij
中创建运行配置来运行此项目,而无需手动运行jar命令?

我们可以通过多种方式运行Java应用程序。常用的是命令行或IDE本身

从命令行

  • java-jar
    命令

    示例:
    java-jar-jar-name.jar

  • java-cp
    命令

    示例:
    java-cp jar-name.jar com.package.ClassName

  • 其中
    com.package.ClassName
    是包含运行程序的主方法的类。上面命令中的cp代表类路径

    来自IDE

    只需在类中单击鼠标右键,就可以找到运行代码的选项。只要点击这个选项。查看此图像以了解详细信息


    您是否尝试从IDE运行主类?主线上通常有一个绿色图标…这表明您可以直接从那里执行它…顺便说一句:
    mvn clean安装
    不仅是必要的
    mvn clean package
    …谢谢,右键单击主线是最好的方法吗?