java 为什么“mvn assembly:single”会创建一个只有程序集而不是我的代码的胖罐子?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7862249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:45:11  来源:igfitidea点击:

Why does "mvn assembly:single" create a fat jar with just the assemblies and not my code?

javamaven-2maven-assembly-plugin

提问by Justin Dearing

I have a maven project I created with spring roo. When I run mvn assembly:singleI get a fat jar with all the dependencies, but not the actual code I wrote. Here is my maven-assembly-plugin configuration from my pom.xml:

我有一个用spring roo创建的 maven 项目。当我运行时,mvn assembly:single我得到一个包含所有依赖项的胖 jar,但不是我编写的实际代码。这是我的 pom.xml 中的 maven-assembly-plugin 配置:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>net.justaprogrammer.poi.cleanser.Cleanser</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

What am I doing wrong?

我究竟做错了什么?

采纳答案by Justin Dearing

The solution is to add the single goal to the package phase of the project life cycle. This means you have to add the following xml under the configuration section:

解决方案是将单一目标添加到项目生命周期的打包阶段。这意味着您必须在配置部分下添加以下 xml:

            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>

回答by B.Mr.W.

I will say what you have done are totally enough. Instead of assembly:single, do:

我会说你所做的已经完全够了。而不是组装:单一,做:

mvn clean compile assembly:single

And you should be good to go.

你应该很高兴去。

回答by matt b

Well, jar-with-dependenciesdoes exactly what you describe is happening. Why don't you just use mvn package?

好吧,jar-with-dependencies正是您所描述的正在发生。你为什么不直接使用mvn package