pom 的<executable>标签
时间: 2023-07-09 22:03:44 浏览: 51
在 Maven 中,<executable> 标签用于指定可执行文件的名称或路径。通常,这个标签用于打包可执行的 JAR 文件时,指定 JAR 文件的入口点。
例如,如果你的项目中有一个名为 com.example.Main 的 Java 类,作为入口点,你可以在 pom.xml 文件中添加以下代码:
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
<manifest>
<mainClass>com.example.Main</mainClass>
</manifest>
</archive>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
```
在这个例子中,<executable> 标签被设置为 true,表示生成的 JAR 文件可以直接运行。在命令行中可以使用以下命令来运行它:
```bash
java -jar example.jar
```
注意,<executable> 标签只在打包可执行 JAR 文件时才有用。如果你的项目没有这个需求,可以忽略它。