准备罐子时将包装包括在Maven中 [英] include package in maven while preparing jar

查看:120
本文介绍了准备罐子时将包装包括在Maven中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下项目结构.我想准备一个带有依赖项的jar,其中包括具有.java文件的不同程序包.

I have below project structure. I wanted to prepare a jar with dependencies including different packages which has .java files.

项目结构:

src/com/rev/automation/utilities
src/com/rev/automation/testdata
src/com/rev/automation/pages

主类:

org.openqa.selenium.remote

如何在Maven的jar中包含"src/com/rev/automation"软件包?我正在使用以下代码准备jar,但其中不包括"src/com/rev/automation"中存在的软件包和文件.请建议

How to include "src/com/rev/automation" packages into the jar in maven? i'm preparing the jar using below code, But it is not including packages and files present in "src/com/rev/automation". Kindly suggest

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <!-- get all project dependencies -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!-- MainClass in mainfest make a executable jar -->
                    <archive>
                        <manifest>
                            <mainClass>org.openqa.selenium.remote.RemoteWElement</mainClass>
                        </manifest>
                    </archive>

                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- bind to the packaging phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

推荐答案

在使用Maven时,您需要遵循

While using Maven, you need to follow the Maven Standard Directory Structure.
In your case, create a folder structure like src/main/java and put all your code in java directory. So it should now look like src/main/java/com/rev/automation etc.
If you follow this structure, then your package will get included in the jar.

更新:

如果您绝对不想/不能做上面提到的事情,或者,您可以使用

If you absolutely don't want to / cannot do what is mentioned above, alternatively, you can use the Maven Build Helper plugin. This will tell maven to include the specified directory as an additional source directory.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src</source>     // specify your directory here
                    ...
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

这篇关于准备罐子时将包装包括在Maven中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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