Maven2& Swing项目:Build&跑步申请 [英] Maven2 & Swing projects: Build & run swing application

查看:181
本文介绍了Maven2& Swing项目:Build&跑步申请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to find info on how to use maven to build and run a swing application but couldn't find anything useful (maven documentation is a mess).

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

Can someone point me to relevant documentation? Is anyone using maven in swing development ?

推荐答案

我猜你想从maven命令运行你的应用程序。您可以使用 exec 插件,如下所示:

I'm guessing that you want to run your app from a maven command. You can use the exec plugin like this:

<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>

您的pom中也可能需要这个。

You may need this in your pom as well.

<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>

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

The actual configuration may vary, depending on which version of the exec plugin you actually end up using - I've had success with some versions, but no success with others, so it's kind of trial and error to figure out the right version of the jar for your project. It's also kind of a pain if you have multiple developers, as arguments for one dev may not be correct for another, so it may be better just writing a batch/shell script to start the app.

为了完整起见,这里有一些示例代码,用于使可执行jar文件与romaintaz的答案中的链接一起使用。

Just for completeness, here's some sample code to make an executable jar file to go with the link in romaintaz's answer.

<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>

这篇关于Maven2&amp; Swing项目:Build&amp;跑步申请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆