2

I stumbled with this issue today, the jar is packaged with all the necessary libs that the program uses (I'm using mvn clean compile assembly:single) and this POM configuration:

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <finalName>${project.artifactId}-${project.version}</finalName>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>fully.qualified.MainClass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>

    </plugins>
</build> 

The error(s) that show up are different, sometimes is the NoSuchMethod like the libraries weren't there but I decompress the jar and there they are, another error is NoSuchFieldError, but then again the jar and the program is the same, only when recompiled on that PC that I'm testing the program/jar it works.

So it's probably a thing from the IDE/environment config problem than my jar (that's my guess I can't really explain in other way).

What could the issue be?

Edit: added POM dependencies

</dependencies>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.9.3</version>
    </dependency>

    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.1</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
    </dependency>

</dependencies>
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Progs
  • 1,059
  • 7
  • 27
  • 63
  • what kind of dependencies do you have in your pom.xml? – Sean Patrick Floyd Jun 03 '16 at 16:16
  • added that info on the post – Progs Jun 03 '16 at 16:18
  • It could be due to the way you pack the jar, it could be because of your PATH variables versus others' and maybe you packaged files which you read in inside of your jar? – Roel Strolenberg Jun 03 '16 at 16:19
  • @RoelStrolenberg How i can check that? i'm packing the jar like this : http://stackoverflow.com/questions/10019549/how-to-eclipse-maven-install-build-jar-with-dependencies – Progs Jun 03 '16 at 16:21
  • 1
    Sometimes, the JVM cannot locate certain resources such as dependent jars inside another jar. To overcome this problem, you can build a fat jar instead that contains all the classes required, flattened out to a single jar file. You can do this yourself, or there are tools such as sbt-assembly or sbt-onejar that allow you to do just that. – ManoDestra Jun 03 '16 at 16:22
  • If you run `mvn clean compile assembly:single` you never reach the package-phase, hence the maven-shade-plugin is never called. I expect that the maven-shade-plugin results in a better fat jar compared to the maven-assembly-plugin, don't forget to mention the main-class here (https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html) – Robert Scholte Jun 03 '16 at 17:56
  • Do those other PCs have the same JRE version? – Roman Jun 05 '16 at 02:41
  • @Roman yes, same version of java – Progs Jun 06 '16 at 14:19
  • You said that the errors differ among various machines. Still it might be interesting to see one example of a stacktrace. Could you please provide one? –  Jul 22 '16 at 13:31
  • @ThomasKuenneth the issue was solved repackaging all the jars with a new version number. not really sure about if it this was a real solution. – Progs Jul 22 '16 at 16:12

0 Answers0