Java Maven Swing图形用户界面:未知生命周期阶段

lskq00tm  于 2023-03-17  发布在  Maven
关注(0)|答案(2)|浏览(197)

我从Maven和Swing开始。我想用Maven创建一个基本的登录表单GUI。当我运行mvn clean package时,我没有遇到任何错误
但是当我运行mvn exec:java -Dexec.mainClass="com.tp14.LoginForm"时,我得到了这个错误:

[ERROR] Unknown lifecycle phase ".mainClass=com.tp14.app.LoginForm". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: pre-clean, clean, post-clean, validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy. -> [Help 1

我不知道该怎么办
下面是我的项目树结构的屏幕:

下面是我的LoginForm代码:

package com.tp14;
import javax.swing.*;

public class LoginForm extends JFrame {
    public LoginForm() {
        setTitle("Login Form");
        setSize(300, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        add(panel);

        JLabel userLabel = new JLabel("Username:");
        JTextField userText = new JTextField(20);
        panel.add(userLabel);
        panel.add(userText);

        JLabel passwordLabel = new JLabel("Password:");
        JPasswordField passwordText = new JPasswordField(20);
        panel.add(passwordLabel);
        panel.add(passwordText);

        JButton loginButton = new JButton("Login");
        panel.add(loginButton);
    }

    public static void main(String[] args) {
        LoginForm loginForm = new LoginForm();
        loginForm.setVisible(true);
    }
}

下面是我的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>com.tp14</groupId>
  <artifactId>tp14</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>tp14</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.swinglabs</groupId>
      <artifactId>swingx</artifactId>
      <version>1.6.1</version>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-                    core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

我试着重命名文件,把它放在另一个文件夹,重新运行mvn清洁包,但没有任何工作。当我手动运行。jar文件,它也没有做任何事情。
多谢了

kiayqfof

kiayqfof1#

如果你在powershell上这样做,你可能只是错过了参数周围的引号。

qyswt5oh

qyswt5oh2#

您可能尝试使用maven插件org.codehaus.mojo:exec-maven-plugin,但没有在pom.xml文件中指定它。
您至少应该将这个代码段“合并”到您的pom.xml文件中:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>3.1.0</version>
    </plugin>
  </plugins>
</build>

不要试图将<plugin>及其子元素添加到已有的元素旁边,因为您只在<pluginManagement>元素中指定了“plugins”,这意味着这些设置如果 * 您在<plugins>元素(<build>元素的直接子元素)中指定这些插件,则 * 将使用它们的版本。(注意复数和单数形式!)
但是请参阅documentation of the MojoHaus Exec Maven Plugin,了解如何改进其配置,以便不必在每次执行时都指定主类。
实际上,我建议您配置maven-jar-plugin以添加清单,以便构建项目的可执行JAR文件,但有关此问题的详细信息还远远不够。

相关问题