Maven project giving error

870 Views Asked by At

After setting up the project in intellij as a maven project like so .. enter image description here

I set up my pom.xml file with a basic structure ...

<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>com.yourcompany.test</groupId>
    <artifactId>jreddit-testing</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>jreddit-testing</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


    <dependencies>
        <dependency>
            <groupId>com.github.jreddit</groupId>
            <artifactId>jreddit</artifactId>
            <version>1.0.2</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    </project>

when I run sudo mvn clean install it installs everything with no errors.

On running the project I get the Error ..

Error:java: directory not found:
/Users/stingRay/Documents/workspace/jreddit/target/generated-sources/annotations
1

There are 1 best solutions below

0
On

Not sure if this will solve your issue but the comments have not enough space :)

I would argue the environment variables are simply not properly configured. I recommend not using sudo and maven. It is simply not necessary if everything is configured properly.

The download page of maven contains the instructions what to do: http://maven.apache.org/download.cgi (scrolling down)

In short:

  • Download the Java Development Kit (I don't use the packet manager from Linux for this, to prevent having root being able to execute Java commands or run servers accidentally). It looks you are working on MacOS? So Download the dmg file from oracle.
  • Download the Maven archive and extract it (it can also be in a shared dirctory so it is readable for every user on the system)
  • the important part: setting the environment variables. You must set JAVA_HOME, M2_HOME, optionally MVN_OPTS and the PATH for convenience - so "mvn" runs in your terminal without sudo.

There are tutorials on the web that guide you through this, like this one: http://bitbybitblog.com/environment-variables-mac/

If you work with IntelliJ or the terminal the .bash_profile file be enough. Editing the .plist file is for OSX internal tools only. In IntelliJ it will work once the M2_HOME variable is set (if I remember correctly) and IntelliJ is restarted.

Note you may need to clean up the files already around (to make sure your user can write them without sudo). Meaning:

  • /Users/stingRay/Documents/workspace/jreddit/target/
  • /Users/stingRay/.m2/repository (or where your local maven repo is located)

Hope that will work :)