No compile errors but still cannot find symbol on Maven - java

I am having a weird issue. I added an interface in a different module, and the IDE compiles fine and everything works fine when I run it on my IDE, but when I do mvn clean install I get an error saying cannot find symbol MyInterface. Here is the log of the mvn clean install:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/path/to/MyClass.java:[5,37] cannot find symbol
symbol: class MyInterface
location: package path.to.where.interface.lives
[INFO] 1 error
[INFO] -------------------------------------------------------------
And the line in MyClass.java where it's complaining about is:
import path.to.where.interface.lives.MyInterface;
And my interface looks like this:
package path.to.where.interface.lives;
public interface MyInterface {
public void method();
}
I even added the dependency to the path.to.where.interface.lives package, in the pom file of where MyClass.java lives, but I am still seeing the issue.

I was able to resolve this issue by running mvn clean install on the entire project first, as I was originally running mvn clean install only on a specific module.

Related

Maven project - compilation errors after cloning

I have a maven project that works perfectly fine locally but after I've pushed it to a remote repository on GitHub and cloned it somewhere else (even to a new location on the same computer), one of the imports does not work because
Cannot resolve symbol 'DefaultMouseManager'
and of course maven install is failing with a lot of compilation errors like this one:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/.../CustomMouseManager2.java:[6,36] cannot find symbol
symbol: class DefaultMouseManager
location: package org.graphstream.ui.view.util
Is there anything I should check that may cause this problem?
Is the problem the class DefaultMouseManager or is it something more general?

Maven clean package, error about not found symbol for "Invalid PropertyValueException"

By executing a mvn clean package I see a strange maven output:
[ERROR] /home/user/Desktop/mycompany/myapp/server/src/main/java/com/mycompany/myapp/representation/rest/RestControllerAdvice.java:[8,38] error: cannot find symbol
[ERROR] symbol: class InvalidPropertyValueException
[ERROR] location: package com.mycompany.myapp.exception
So, I searched the row nr. 8 in that class and I found this one
import org.springframework.web.bind.annotation.ExceptionHandler;
But, the line which is referred to InvalidPropertyValueException is 2 rows before:
import com.mycompany.myapp.exception.InvalidPropertyValueException;
And, the strange thing, in the package com.mycompany.myapp.exception I didn't found any class or file named InvalidPropertyValueException. But Eclipse accept it and present me in the option list. And this class don't generate any error or red line.
Try maven->update project this error may go out.
On Project Explorer, right-click on the parent module
select maven, then select Update Project

Use non-maven jar in maven project (using command line)

To start, I do not know much about maven or even jar's in general...
So basically I have been given a jar that was not created with maven to use in my maven project
Inside it has in it some classes:
com/something/types/Foo.class
com/something/types/Bar.class
com/something/utils/Foou.class
com/something/utils/Baru.class
etc.
I have tried running the following:
mvn install:install-file -Dfile=something.jar -DgroupId=com.something.somethingelse \
-DartifactId=somethingelse -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
and it says build success and has created the following:
~/.m2/repository/com/something/somethingelse/somethingelse/1.0/somethingelse-1.0.jar
~/.m2/repository/com/something/somethingelse/somethingelse/1.0/somethingelse-1.0.pom
in my project's pom I have included the following:
<dependency>
<groupId>com.something.somethingelse</groupId>
<artifactId>somethingelse</artifactId>
<version>1.0</version>
</dependency>
In my project I import like so:
import com.something.types.Foo
import com.something.utils.Foou
etc.
But when I run mvn install on my project I receive errors like the following every time I try to use something from the jar?
[ERROR] {{ProjectClass.java}}[line,col] cannot find symbol
[ERROR] symbol: class Foo
[ERROR] location: class ProjectClass
Please help! I do not use eclipse.
This process worked fine. The errors ended up being mistakes in my java code. For example:
import com.something.types.Foou // my old code
import com.something.utils.Foou // working import

Maven jar dependency issue package not found on OpenShift server

I'm getting a dependency issue with a jar I'm attempting to use.
I receive the following error
remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project sparq: Compilation failure: Compilation failure:
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[3,0] error: package com.github.koraktor.steamcondenser does not exist
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[8,8] error: cannot find symbol
remote: [ERROR] class ServerQuery
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[8,34] error: cannot find symbol
Here is the offending java file.
package helpers;
import com.github.koraktor.steamcondenser.*;
public class ServerQuery {
public static String getPlayers() {
SourceServer server = new SourceServer("66.150.155.152",27015);
server.initialize();
return server.toString();
}
}
I've added the following dependency to my pom.xml
<dependency>
<groupId>com.github.koraktor</groupId>
<artifactId>steam-condenser</artifactId>
<version>1.3.9</version>
</dependency>
I've also added the following action_hook pre_build script
mvn install:install-file -Dfile=./app-root/repo/steam-condenser.jar -DgroupId=com.github.koraktor -DartifactId=steam-condenser -Dversion=1.3.9 -Dpackaging=jar
Here's the GitHub for the project
https://github.com/koraktor/steam-condenser-java
And the website for it
http://koraktor.de/steam-condenser/usage/
Any ideas? Completely lost. Help much appreciated.
Since you are including the jar file in your project already, trying to manage the dependency with Maven seems like overkill. You should be able to put the jar file in your project's lib directory like this article describes. Then you won't need to configure that dependency in Maven at all.
I would use Maven for any dependencies that you want to download at the time your application is being built. Any jar files that you are checking into your project shouldn't need to be configured in Maven.
Just by looking at the question and the excerpts provided, I believe you are struggling with the basics of Maven. If I understand the situation correctly you have a library (which is not written by you):
once added to your project as a Maven dependency. This seems reasonable if you want to use it.
once the source code of the library incorrectly added to your own Java project.
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[3,0] error: package com.github.koraktor.steamcondenser does not exist
Based on the errormessage above it seems you have copied one of the sourcefiles from the library into your project. This is now causing problems. The main one is that without your source-folder (src/main/java) correctly representing the package structure declared in the source file (com.github...) it cannot be compiled. Hence the errormessage:
package com.github.koraktor.steamcondenser does not exist.
First of all you need to remove this copy-pasted file entirely an just use the dependency-management feature of Maven to get the library on classpath. After that just follow the examples given by the author of the library using the link you have already found (http://koraktor.de/steam-condenser/usage/).

Error: Package does not exist

I have a little problem in Eclipse with a package . The error output is Package (name of package ) does not exist .
I have a package called de.baimos.blueid.lockserver.demo.exec . But Eclipse is looking for a package called de.baimos.blueid.lockserver.api.exec . This package is can be found in my Project nowhere .
My current situation is this: I have two projects that work as a project. Now you can in Eclipse under Properties - Add a project to a different > Project -> Java Build Path . But if I want to run Maven install I get the error above. At first I thought it would be in the pom.xml file . But I noticed that it is not possible to merge two pom.xml files. My project was to make the inheritance , however, by themselves , whom I put them together leads . Did anyone of you ever such a problem , or can someone help me ?
Thanks in advance for your help .
That is the error:
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[3,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[4,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[5,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[6,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[8,59] error: cannot find symbol
Maven can't see what you specify in Eclipse's Java Build Path; it's a command line tool that runs outside / without Eclipse.
Instead, you have to do mvn install in the first project.
Then you can add a dependency to this project in the second project's POM.
Maven will then make sure that Eclipse add the first project to the classpath as well without manually changing the build path in the UI.

Categories

Resources