45

I have a (seemingly) simple maven problem I can not solve. In my POM I have specified a dependency to openrdf-sesame like this:

<dependency>
     <groupId>org.openrdf.sesame</groupId>
     <artifactId>sesame-runtime</artifactId>
     <version>2.7.2</version>
</dependency>

Running the project from eclipse works well, I can even export a runnable jar file. Unfortunately, I cant get it to work properly via cmd-line maven. To build a jar, I have added the following to my pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>foo.bar.Cli</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

The compilation fails with the following errors:

.../PLDReducer.java:[25,29] package org.openrdf.rio.rdfxml does not exist
.../PLDReducer.java:[27,33] package org.openrdf.sail.nativerdf does not exist
.../LowPLDReducer.java:[25,29] package org.openrdf.rio.rdfxml does not exist
.../Cli.java:[23,33] package org.openrdf.sail.nativerdf does not exist
.../SchemaBuilder.java:[30,33] package org.openrdf.sail.nativerdf does not exist
.../RepoQuerier.java:[23,33] package org.openrdf.sail.nativerdf does not exist
.../PLDReducer.java:[78,44] cannot find symbol

Strangely, as soon as I add the compile plugin to the pom and update project settings, eclipse cant seem to compile anymore as well. I have checked my repository, and all sesame files are in there.

mvn --version gives this output:

Apache Maven 2.2.1 (rdebian-8)
Java version: 1.6.0_27
Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.8.0-25-generic" arch: "amd64" Family: "unix"

I see that it seems to point to a jre, but my googling indicated that I would see another error if the compiler itself was not found. I have pasted the complete POM here, if it is of any help.

Is there anything I am missing? I can't find any errors in my POM.

Gawron
  • 85
  • 1
  • 11
feob
  • 1,930
  • 5
  • 19
  • 31
  • Can you show the full output of the 'mvn clean package'? – khmarbaise Jun 22 '13 at 12:55
  • [Here is with -e switch](http://pastebin.com/zg24L8rS) and [Here with -X switch](http://pastebin.com/A5G613LL) – feob Jun 22 '13 at 13:28
  • It looks your are using package names (presumbly in your import part) which do not exist. Do you really need thoose packages? Using classes from it? Cleaned up the import part with IDE (like Eclipse?)? Can you show one of the source code files like `PLDReducer.java` ? – khmarbaise Jun 22 '13 at 13:39
  • [PLDReducer.java](http://pastebin.com/0Q1kCM3s) - I definately use the openrdf packages, and I am pretty sure they are correct. I can compile and run my project fine from eclipse. – feob Jun 22 '13 at 13:44

4 Answers4

21

You have to add the following dependency to your build:

<dependency>
    <groupId>org.openrdf.sesame</groupId>
    <artifactId>sesame-rio-api</artifactId>
    <version>2.7.2</version>
</dependency>

Furthermore i would suggest to take a deep look into the documentation about how to use the lib.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks, this actually did the trick! But if this additional module is required, how is it possible that the project compiles and runs from within eclipse? I do not have any jars in lib folder or similar. Also, the linked document seems great, I have not come across this yet! – feob Jun 22 '13 at 14:27
  • 17
    The missing packages are runtime dependencies, which is why compilation from the command line fails. However, the Maven Eclipse plugin tends to ignore scoping rules and just pull every dependendency, which is why compilation from Eclipse will work without problems. – Jeen Broekstra Jun 23 '13 at 09:58
  • Which kind of scope did you defined ? – khmarbaise Jun 24 '13 at 18:09
  • @khmarbaise - link in your answer is broken (http://openrdf.callimachus.net/sesame/2.7/docs/users.docbook?view#chapter-lib-install) Could you please update working link if possible – Santosh Kumar Sep 21 '21 at 03:15
5

You do not include a <scope> tag in your dependency. If you add it, your dependency becomes something like:

<dependency>
     <groupId>org.openrdf.sesame</groupId>
     <artifactId>sesame-runtime</artifactId>
     <version>2.7.2</version>
     <scope> ... </scope>
</dependency>

The "scope" tag tells maven at which stage of the build your dependency is needed. Examples for the values to put inside are "test", "provided" or "runtime" (omit the quotes in your pom). I do not know your dependency so I cannot tell you what value to choose. Please consult the Maven documentation and the documentation of your dependency.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Martijn Dirkse
  • 543
  • 7
  • 16
  • 1
    just had the same problem and I removed the all together and it built the project successfully. – Damien-Amen Apr 28 '16 at 01:33
  • For me, removing scope did not work. I am getting same package does not exist error for org.apache.log4j from command line - mvn clean install. Works will when running testng.xml from intellij – MansoorShaikh Nov 29 '19 at 08:28
3

Not sure if there was file corruption or what, but after confirming proper pom configuration I was able to resolve this issue by deleting the jar from my local m2 repository, forcing Maven to download it again when I ran the tests.

eebbesen
  • 5,070
  • 8
  • 48
  • 70
2

the issue happened with me, I resolved by removing the scope tag only and built successfully.

Fahd Allebdi
  • 354
  • 4
  • 7