Netbeans Maven:Java 应用程序在多次运行时会创建多个实例(每次运行一次),从而导致端口冲突



我通常使用JEE和Glassfish来创建Web应用程序,但是我使用Jetty创建了一个不需要容器的Web应用程序。但是,每次运行应用程序时,我都必须手动停止当前正在运行的实例。这不会花很长时间,但有点痛苦。我想要一个更平滑的开发周期,我相信它可以在命令行上自动化并且会这样做,但我认为这应该是一个非常普遍的问题。

我正在使用 NB 8.2 创建我的项目。 文件 -> 新项目 -> 在"类别"下选择"Maven",在项目"Java 应用程序"下

每次运行项目时,都会部署一个新的正在运行的实例,这样在运行 5 次之后,有 5 个正在运行的程序(这种类型的应用程序通常是这种情况,但由于端口冲突,我必须停止前一个实例(。

以下任何一种都是可行的解决方案:

  1. 理想情况下,如果有一个正在运行的程序实例,它会在保存时编译并重新启动,不知道这是否可以在像 Glassfish 这样的容器之外。
  2. 应用程序会终止任何以前的部署,并在按下"运行项目"按钮 (F6( 时编译并运行新实例。
  3. 任何其他符合此意图的东西。

对于基于pom的解决方案,这是我正在使用的:

<?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.kenmcwilliams</groupId>
<artifactId>MpawServices</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<!-- Web dependencies -->
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
<type>jar</type>
</dependency>
<!-- JSON parsing -->
<dependency>
<groupId>io.fastjson</groupId>
<artifactId>boon</artifactId>
<version>0.34</version>
</dependency>
<!-- needed for DB access -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.6.0</version>
</dependency>
<!-- needed for Dagger2 DI -->
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.11</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.11</version>
<optional>true</optional>
</dependency>
<!-- to prevent: SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder” -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.kenmcwilliams.mpawservices.App</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

我认为目前NetBeans 中没有这样的功能,但您应该能够在 NetBeans Jira Issue Tracker 上提交功能请求。事实上,这将是一个不错的功能,我过去也搜索过类似的东西。

相关内容

最新更新