Maven2&Swing项目:构建和运行swing应用程序

jav*_*ito 11 java build-automation swing maven-2

我试图找到有关如何使用maven来构建和运行swing应用程序的信息,但找不到任何有用的东西(maven文档很乱).

有人能指出我的相关文件吗?是否有人在摇摆开发中使用maven?

Mat*_*inn 15

我猜你想从maven命令运行你的应用程序.您可以像这样使用exec插件:

<build>
    <plugins>    
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1-beta-1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.package.MainClass</mainClass>
                <arguments>
                    <argument>arg1</argument>
                    <argument>arg2</argument>
                </arguments>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

你也可以在你的pom中使用它.

<repositories>
    <repository>
        <id>Maven Snapshots</id>
        <url>http://snapshots.maven.codehaus.org/maven2/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>Maven Snapshots</id>
        <url>http://snapshots.maven.codehaus.org/maven2/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>
Run Code Online (Sandbox Code Playgroud)

实际配置可能会有所不同,具体取决于您最终使用的exec插件的版本 - 我已经在某些版本上取得了成功,但在其他版本上没有成功,因此找出合适的版本是一种试验和错误. jar为您的项目.如果你有多个开发人员,这也是一种痛苦,因为一个开发者的参数可能对另一个开发者来说不正确,所以最好只编写一个批处理/ shell脚本来启动应用程序.

为了完整起见,这里有一些示例代码,用于生成可执行jar文件以及romaintaz的答案中的链接.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.package.MainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)