<dependencies> <dependency> <groupId>com.beust</groupId> <artifactId>jcommander</artifactId> <version>1.78</version> </dependency> </dependencies> import com.beust.jcommander.Parameter; import com.beust.jcommander.JCommander; public class CommandLineTool { @Parameter(names = {"--input", "-i"}, description = "Input file name", required = true) private String inputFileName; @Parameter(names = {"--output", "-o"}, description = "Output file name", required = true) private String outputFileName; public static void main(String[] args) { CommandLineTool tool = new CommandLineTool(); JCommander.newBuilder() .addObject(tool) .build() .parse(args); } } <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.1</version> <configuration> <archive> <manifest> <mainClass>com.example.CommandLineTool</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>


上一篇:
下一篇:
切换中文