0

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

Project Structure:

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

Main Class:

org.openqa.selenium.remote

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>
Sam
  • 543
  • 3
  • 10
  • 27
  • are you really trying to include the source file (`*.java`) to your final JAR? Or are you actually trying to include the compiled class files? Why are you doing it? Tell us what you are trying to achieve so we can suggest a more maven way to you – Adrian Shum Oct 12 '16 at 03:38

1 Answers1

0

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.

Update:

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>
RITZ XAVI
  • 3,633
  • 1
  • 25
  • 35
  • I can't change the folder structure now. It would require more efforts to make it aligned with whatever you said. – Sam Oct 12 '16 at 03:04
  • It hardly needs any efforts. All that you need to do is to just create the "main" and the "java" folder and copy the "com" directory into the java directory. You dont have to change any lines of code. Maven will automatically set things for you. – RITZ XAVI Oct 12 '16 at 03:08
  • @TestGeeK imho Maven is not going to be a good tool for you if you cannot even change your directory structure. In order to use Maven smoothly you gotta follow the conventions (not only the directory structure but other, e.g. how you arrange module, how you look at dependencies etc) – Adrian Shum Oct 12 '16 at 03:41
  • Okay.. Thanks Adrain Shum and RITZ. I will try to change the current project into the structure Maven recommended. – Sam Oct 13 '16 at 12:22