我正在为一所7人组成的大学项目。我们有一个问题,我们有不同的输出,这取决于我们用来编译我们的一个组件。
如果我们使用.class文件,这些文件也是由maven创建的,一切正常。 但是如果我们使用maven创建的jar,我们就会遇到烦人的bug。 特定ArrayList的某些元素会被删除。
代码运行时没有错误,但输出不同。我在文本下面列出了两个输出的例子。
这怎么可能?顺便说一句,如果代码运行jar,则组中的每个人都会获得相同(错误)的输出。我们试图在代码中搜索错误,但一切似乎都很好。我们还仔细检查了pom.xml并尝试了一个具有依赖性且没有依赖关系的jar。
如果您需要有关我们代码的更多信息,请告诉我,但我认为问题与maven或pom有关,尤其是因为如上所述,所有类都可以正常工作。
<!-- 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>
使用.class文件输出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
使用jar 输出command: java -jar target/dbpedia-provenance-1.0-SNAPSHOT-jar-with-dependencies.jar TestInput.txt
或
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
这些只是我们输出的非常小的部分,我猜它恰好喜欢1%的时间戳,只有时间戳。