3

I am working on a Project for my university in a group of 7 people. We have a Problem, that we have different outputs depending on what we use to compile one of our Components.

If we use the .class files, which are also created by maven everything works fine. But if we use the jar which maven creates we get an annoying bug. Some elements of an specific ArrayList get cut.

The Code runs with no errors aswell, but the outputs are different. I put an example of the both outputs below the text.

How is this even possible? Btw everyone of the group get the same (wrong) output if the code runs with jar. We tried to search for errors in the code but everything seems fine. We also double checked the pom.xml and tried to a jar with dependencies and without dependencies.

If you need more information about our code let me know, but I guess the Problem has to do with maven or the pom especially, because with the classes everything works fine as mentioned above.

Pom.xml

<!-- project was generated with
  mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=dbp17 -DartifactId=dbpedia-provenience -->
<!-- for documentation refer to https://maven.apache.org/pom.html#The_Basics -->

<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <!-- name of the author group -->
  <groupId>dbp17</groupId>
  <!-- name of the project,
       together with the groupId it should uniquely identify this project -->
  <artifactId>dbpedia-provenance</artifactId>
  <!-- the result of `mvn package` is a jar file with the compiled sources
    this uses the maven-jar-plugin https://maven.apache.org/components/plugins/maven-jar-plugin/
      This plugin provides the capability to build jars. -->
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <!-- defines properties / variables; https://maven.apache.org/pom.html#Properties
    Maven properties are value placeholder, like properties in Ant.
    Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. -->
  <properties>
    <!-- sets variables for which version of the dependencies to use -->
    <jena.version>3.2.0</jena.version>
    <slf4j.version>1.7.24</slf4j.version>
    <junit.version>4.11</junit.version>

    <!-- sets encoding to UTF-8 for standardized, platform-independent build
      as describe here: https://maven.apache.org/general.html#encoding-warning -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

    <!-- Apache Jena: (from wikipedia:)
        Apache Jena is an open source Semantic Web framework for Java.
        It provides an API to extract data from and write to RDF graphs.
        The graphs are represented as an abstract "model".
      code taken from https://jena.apache.org/download/maven.html -->
    <dependency>
      <groupId>org.apache.jena</groupId>
      <artifactId>apache-jena-libs</artifactId>
      <type>pom</type>
      <version>${jena.version}</version>
    </dependency>

    <!-- for Apache Jena: (from https://www.slf4j.org/:)
        The Simple Logging Facade for Java (SLF4J) serves
        as a simple facade or abstraction for various logging frameworks
        (e.g. java.util.logging, logback, log4j) allowing the end user
        to plug in the desired logging framework at deployment time.
      code taken from https://www.slf4j.org/faq.html#maven2 -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-nop</artifactId>
      <version>${slf4j.version}</version>
      <!-- with this enabled, an error message is thrown
        SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
        SLF4J: Defaulting to no-operation (NOP) logger implementation
        SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
      <scope>test</scope> -->
    </dependency>

    <!-- autogenerated, for Unit Tests with JUnit-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <!-- <scope>test</scope> -->
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <!-- per default maven doesn't build an executable jar
        there are several ways to get maven to build standalone executable jar file
        as explained for example here: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven/#answer-23986765 -->

      <!-- bundle all dependencies together with the project into one big jar
        using the maven-assembly-plugin
        code taken from http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
          sections 'Execution: Building an Assembly' and 'Creating an Executable JAR' -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>DumpParser</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>

output using .class files

command: java -cp target/classes/ DumpParser TestInput.txt

counter  ID\Revisions-IDs    author
81      99248866       Overberg                                2012-02-04T16:08:11Z
82      99248577       Overberg                                2012-02-04T16:00:41Z
83      99248479       Overberg                                2012-02-04T15:58:24Z
84      99248404       Overberg                                2012-02-04T15:56:38Z
85      99248239       Overberg                                2012-02-04T15:52:36Z
86      99214062       Overberg                                2012-02-03T18:08:33Z
87      99207128       Overberg                                2012-02-03T15:04:58Z
88      99205924       Overberg                                2012-02-03T14:32:54Z
89      99205852       Overberg                                2012-02-03T14:31:07Z
90      99198643       Overberg                                2012-02-03T11:48:22Z

output using jar

command: java -jar target/dbpedia-provenance-1.0-SNAPSHOT-jar-with-dependencies.jar TestInput.txt

or

command: java -cp target/dbpedia-provenance-1.0-SNAPSHOT-jar-with-dependencies.jar DumpParser TestInput.txt

counter  ID\Revisions-IDs    author                                   timestamp
81      99248866       Overberg                                2012-02-04T16:08:11Z
82      99248577       Overberg                                2012-02-04T16:00:41Z
83      99248479       Overberg                                2012-02-04T15:58:24Z
84      99248404       Overberg                                2012-02-04T15:56:38Z
85      99248239       Overberg                                2012-02-04T15:52:36Z
86      99214062       Overberg                                201
87      99207128       Overberg                                2012-02-03T15:04:58Z
88      99205924       Overberg                                2012-02-03T14:32:54Z
89      99205852       Overberg                                2012-02-03T14:31:07Z
90      99198643       Overberg                                2012-02-03T11:48:22Z

These are only very small pieces of our output, I would guess it happens to like 1 % of the timestamps and only the timestamps.

Julius K.
  • 33
  • 6
  • 1
    Have you tried manually jaring added the .class files that maven outputs? Curious if you see the same error in that case... – Jason Braucht Mar 09 '17 at 14:41
  • `if we use the .class files, which are also created by maven everything works fine. But if we use the jar which maven creates we get an annoying bug`. Can you explain that a little bit more in detail... – khmarbaise Mar 09 '17 at 14:47
  • @JasonBraucht if we manually create the jar it works too. But only without the dependencies. however we need the dependencies for libraries such as apache jena. – Julius K. Mar 09 '17 at 15:03
  • @khmarbaise As u can see the output with the jar and with the .class files are not equal. The timestamp is cut at a randomly position, which it should not. In detail the SAX Parser looks in the given .xml file for the tag and add the timestamp to the arraylist called timestamplist which is then outputed by the file writer. – Julius K. Mar 09 '17 at 15:07
  • Shouldn't java -cp target/classes/ DumpParser TestInput.txt run into errors because your dependencies are not present? – J Fabian Meier Mar 09 '17 at 15:13
  • Update: creating the jar manually and adding the classpath to the dependencies works. But this is just a workarround and doesn't fix the Problem we have. This also means for some weird reason maven doesn't create the jar the right way. – Julius K. Mar 09 '17 at 15:30
  • @JFMeier We don't need the dependencies for this specific component (DumpParser). Therefore it's even more confusing why it won't work the right way with the dependencies. – Julius K. Mar 09 '17 at 15:33
  • 1
    Are you sure that you have _exactly the same_ classes in both cases? Maybe you compare an old version with a new one. Furthermore, you might hide one of your classes if one of your dependencies has exactly the same class name. It is most likely not a Maven issue. – J Fabian Meier Mar 09 '17 at 15:37
  • @JFMeier yes I'm sure. Also I am not the only one testing these solution. As far as I know the problem is with the pack up of the jar. Im certainly sure that maven is not the problem here, but it causes it for some reason. Therefore I posted the pom.xml file, maybe we did something wrong. It is the first time we are using maven. – Julius K. Mar 09 '17 at 16:00
  • 1
    What version of Maven? What version of dependency and jar plugins? I see a reference to `jar-with-dependencies`. Is the project using the Assembly plugin, and if so, will you please show that plugin config as well? – user944849 Mar 09 '17 at 16:17
  • @user944849 Sorry, we mixed up different pom.xml versions. I edited the post to reflect the current state. `mvn -version` yields: Apache Maven 3.3.9 (NON-CANONICAL_2015-11-23T13:17:27+03:00_root; 2015-11-23T11:17:27+01:00) with the new pom, `mvn -Dplugin=org.apache.maven.plugins: help:describe` yields the following versions maven-assembly-plugin: "3.0.0." maven-dependency-plugin: "3.0.0" maven-jar-plugin: "3.0.2" – Julius K. Mar 09 '17 at 18:44
  • As pointed out by user944849, we mixed up different versions of our pom.xml. Our first attempt was using the maven-dependency-plugin (to copy all the dependencies in the target folder) and the maven-jar-plugin (to add this folder to the classpath in the jar's manifest file). Our second, more recent attempt, is to use the maven-assembly-plugin to bundle the project including all dependencies into one big jar file. The corresponding pom.xml is now added. However, the error itself persists under both different approaches. – Julius K. Mar 09 '17 at 18:45

0 Answers0