首页 文章

在准备 jar 时包括maven包

提问于
浏览
0

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

项目结构:

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

主类:

org.openqa.selenium.remote

如何在maven中将“src / com / rev / automation”包包含在jar中?我正在使用下面的代码准备jar,但它不包括“src / com / rev / automation”中的包和文件 . 请建议

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

1 回答

  • 0

    使用Maven时,您需要遵循Maven Standard Directory Structure .
    在您的情况下,创建一个像 src/main/java 这样的文件夹结构,并将所有代码放在 java 目录中 . 所以它现在应该看起来像 src/main/java/com/rev/automation 等 .
    如果你遵循这个结构,那么你的包将被包含在jar中 .

    Update:

    如果你绝对不想/不能做上面提到的,或者你可以使用Maven Build Helper插件 . 这将告诉maven将指定的目录包含为附加的源目录 .

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

相关问题