【发布时间】:2017-12-16 00:18:29
【问题描述】:
我通常使用 JEE 和 Glassfish 来创建 Web 应用程序,但是我使用 Jetty 创建了一个不需要容器的 Web 应用程序。但是,每次运行应用程序时,我都必须手动停止当前正在运行的实例。这不会花很长时间,但它有点痛苦。我想要一个更顺畅的开发周期,我确信它可以在命令行中自动化并且会这样做,但我认为这应该是一个很常见的问题。
我正在使用 NB 8.2 创建我的项目。 文件 -> 新建项目 -> 在类别下选择“Maven”,在项目下选择“Java 应用程序”
每次运行项目时,都会部署一个新的运行实例,这样在运行 5 次后有 5 个正在运行的程序(通常这种类型的应用程序就是这种情况,但由于端口冲突,我必须停止以前的例子)。
以下任何一种都是可行的解决方案:
- 理想情况下,如果它们是程序的运行实例,它会在保存时编译并重新启动,不知道这在 Glassfish 等容器之外是否可行。
- 当按下“运行项目”按钮 (F6) 时,应用程序会终止任何以前的部署并编译并运行一个新实例。
- 符合此意图的任何其他内容。
对于基于 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>
【问题讨论】: