2

Am compiling my pom.xml file and am getting the below compilation error

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.5.1:copy-dependencies (copy-dependencies) on project ElasticSearchUtility: Error copying artifact from C:\Users\10641516\.m2\repository\org\apache\lucene\lucene-sandbox\7.1.0\lucene-sandbox-7.1.0.jar to D:\Karthikeyan\ElasticSearch\ElasticSearch_Tesing\target\dependency-
    [ERROR] jars\lucene-sandbox-7.1.0.jar: The filename, directory name, or volume label syntax is incorrect

But the required .jar file is available in the specified path.

I have created two java file my maven project one is POJO class and another one is java main class file. I want to make my project as an executable jar file which i want to run externally using java -jar command.

Please find my pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ElasticSearchUtility</groupId>
<artifactId>ElasticSearchUtility</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>rest</artifactId>
        <version>5.1.2</version>
    </dependency>

</dependencies>

<build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                </configuration>
            </plugin>

            <!-- Set a compiler level -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!-- Make this jar executable -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/log4j.properties</exclude>
                    </excludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>ProjectJar.project.App</mainClass>
                            <classpathPrefix>dependency-jars/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <!-- Copy project dependency -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!-- exclude junit, we need runtime dependency only -->
                            <includeScope>runtime</includeScope>
                            <outputDirectory>${project.build.directory}/dependency-
                                jars/</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            </plugins>
    </build>
    </projects>
Karthikeyan
  • 1,927
  • 6
  • 44
  • 109

1 Answers1

1

The sawn off error message:

  ... D:\Karthikeyan\ElasticSearch\ElasticSearch_Tesing\target\dependency- 

suggests that you need to change the outputDirectory configuration of the maven-dependency-plugin to:

                    <configuration>
                        <!-- exclude junit, we need runtime dependency only -->
                        <includeScope>runtime</includeScope>
                        <outputDirectory>
                            ${project.build.directory}/dependency-jars/
                        </outputDirectory>
                    </configuration>

to get rid of the newline in the middle the value.

Steve C
  • 18,876
  • 5
  • 34
  • 37
  • Thankyou., it fixed my issue., now am getting this error while executing my jar file `Error: Could not find or load main class ProjectJar.project.App`. My main class package name is `com.es.utility.DocumentIndex` so do i need to give my full package name instead of `ProjectJar.project.App`..? (in my pom.xml file) – Karthikeyan Jul 08 '18 at 06:35
  • If i add `com.es.utility.DocumentIndex` am getting `Error: Could not find or load main class com.es.utility.DocumentIndex` error – Karthikeyan Jul 08 '18 at 12:52
  • This sounds like a new question. We don't have much chance of answering this based upon the information provided. – Steve C Jul 08 '18 at 13:05
  • I have created a separate question for this error - https://stackoverflow.com/questions/51232734/error-could-not-find-or-load-main-class-while-executing-jar-file – Karthikeyan Jul 08 '18 at 14:02