Posts Tagged ‘maven’

Cannot resolve symbol XYZ in IntelliJ although maven builds sources properly

Today I stumbled upon a weird problem with IntelliJ IDE.

I had to update one of maven dependencies version, which introduced a new class I wanted to use.
It was possible to build the project without any problem by mvn install, but still the editor marked it red with message ‘cannot resolve symbol’.
Consequently it was for instance impossible to run single unit tests from IDE, because IntelliJ considered this code as invalid to compile.

I tried invalidating caches, reloading pom.xml etc. but to no avail.

Finally it turned out that for some reason IntelliJ is incapable to track changes in maven artifacts versions, if the version is given in a variable like :

<dependency>
      <groupId>com.jetdrone</groupId>
      <artifactId>yoke</artifactId>
      <version>${yoke.version}</version>
    </dependency>

The workaround goes as follows :

1. Replace ${yoke.version} with raw string version
2. Go to File -> Settings … -> (search) maven -> repositories and click ‘Update’ on your local maven repository.
3. Invalidate caches. (File -> Invalidate caches / restart … )
4. Now it should work
5. You can replace tag content with variable reference again

I wasted quite a lot of time for that, so maybe it will help someone with similar issue 😉

I get “Unable to locate the Javac Compiler” when trying to build using IAM Maven Eclipse plugin.

Problem:
When trying to build maven project using IAM under Eclipse I get an error like this:


"Unable to locate the Javac Compiler in:C:\\Program
Files\\Java\\jre6\..\\lib\\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable"

,nevertheless I have proper installation of newest Java JDK and JAVA_HOME is properly set.
The problem never occured before.

Solution:

I know two possible causes of that problem:

1. Eclipse uses its own JRE to start, and IAM does the same. You’ve recently installed a new maven plugin and it requires JDK.
You can force Eclipse to start using directly given Java VM by starting it that way from command line:

“X:\\path\to\\eclipse\\eclipse.exe -vm JAVA_JDK_PATH”

2. There also cases when IAM brokes up without apparent cause, and that happend to me.
The reason may be IAM itself.
Try standard tricks checklist from my another post here:
Problems using Eclipse IAM and Maven

I get NoClassDefFound for ContextLoaderListener class using Spring and Eclipse IAM Maven plugin

My most common headache during my last Spring project was:


java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

during start of Tomcat.

Every source pointed to problems with spring.jar, so I suspected having some version conflict between my Spring libraries (eg. I used also Spring-WS in an old version). But that wasn’t real cause and I’d wasted a lot of time. The real problem was faulty Eclipse IAM plugin.

Try out some tricks I’ve described in my another article : Problems using Eclipse IAM and Maven

They really may help you.

Problems using Eclipse IAM and Maven

During my last project I was involved, I used Eclipse IAM plugin for integration with Maven. It caused many problems, mainly Class not found exceptions and issues with Tomcat server.

Generally I perceived that Eclipse IAM tends to lose jars from pom.xml, what leads to unexpected, bizarre time wasting NoClassDefFoundError.

Unfortunately I hadn’t been sucessful in finding causes of my problems but I’d like to share with you my standard ‘IAM problems checklist’ 😉

If you have any problems try this (in specified order) :

  1. Use refresh, then fetch source jars option from maven menu.
  2. Try cleaning maven libraries, then do ‘1.’
  3. After doing ‘2.’, remove your app from Tomcat, clean server, then deploy again.
  4. Try removing whole server, then add it again.
  5. REMOVE AND REGENERATE WHOLE WORKSPACE

Any step mentioned above is not a joke. I had really to ‘reset’ workspace a few times to make things work again.. First three steps helped me in 80% cases.

I hope my tips will save your time.