Maven dependencies are downloaded but not recognized inside project - java

I want to build a project which has some external libraries. I included pom.xml file inside intellij and it downloaded all of required dependencies files from maven and put them as external libraries, but my project doesn't recognize them and gives compilation error. IDE screen attached below.
this is one of the compilation errors that I get:
Error:(29, 33) java: package com.google.common.collect does not exist
here is the my external libraries which I think are added correctly.
I don't have maven installed but I think IntelliJ handles it by it self.

Have you tried running mvn clean compile either using Intellij or command line ?

Related

Maven Install Cannot Find Packages

I'm trying to build an existing project using Maven on Eclipse. It uses a lot of jar files which I've downloaded years back.
Eclipse seem to recognize these jar files on build(no warnings/errors on editor) but when I do Run > Run As... > Clean Install, it shows a lot of compile errors(i.e. package org.apache.log4j does not exist, cannot find symbol)
It looks like Maven is not including may jar files on build. Any suggestion on how to include this in POM.XML? I tried playing with but does not seem to work.
Note: I've been doing this on ANT, I just include the jar folder in my build.xml and it gets picked up.
Failed Solution 1:
Tried downloading each of the missing jars via adding it on dependency(copy pasted from maven repo site). This seemed an impractical solution and also some of the jars are not on maven repo anymore.
Failed Solution 2:
Tried playing with localRepository but does not do anything.
Failed Solution 3:
Used Add Dependency interface on eclipse but nothing shows on the search reults.

Unable to import the Maven module in Intellij

I am trying to open this module in Intellij:
https://github.com/eugenp/tutorials/tree/master/javaxval
The steps followed by me:
Go to required directory javaxval/ in my local and
mvn clean install.
Open the pom.xml inside javaxval/ and open it as a project.
But Intellij is not syncing with the libraries mentioned in pom.xml as I can see in libraries section in Project Structure settings. Also, because of that, I can see lot of compilation errors.
Any idea what is the issue I am facing and how can I fix it?
This project imports and builds fine in IntelliJ IDEA 2019.2.2 version using the bundled Maven 3.6.1 for importing and JDK 1.8.
If it doesn't import/build for you, perform the diagnostics and check the logs as described in this answer. Make sure the parent pom file is present in the directory tree on your disk.

GWT maven build eclipse

I had a GWT app, and I wanted to automate its build and deploy system, since I do it manually. But I did not find a way how to build the app from command line, so it can than be automated. I had to click the Google button, then compile GWT project and then click Compile.
I found out that it is possible to create a GWT maven project and that it should then be possible to compile my project from commandline with mvn gwt:compile.
So I created a new project using this plugin. Copied my sources from the old project to this new one.
Now the structure is like this:
/src
---/main
------/java -> here are all my sources including my Project.gwt.xml file.
------/webapp
---/test
pom.xml
Now I have 2 problems.
1. I thought that I add dependencies to the pom.xml, and then when I build the app, it will create the jars and I can use those libraries in my GWT app. I guess 'mvn clean install' should do this, but so far I'm getting compile errors.
2. I did not get mvn clean install to work, so I added all the jars manually again... And then yes! I was able to build the app using the plugin GWT button! So I was thinking that now I can use 'mvn gwt:compile', but it fails with:
Unable to find: "com/company/project/Project.gwt.xml" on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
EDIT:
So I fixed my <moduleName> element in pom.xml, so now it finds the Project.gwt.xml. I'm trying to run:
mvn clean install gwt:compile
But I am getting compile errors. I think, it tries to build my project without the actual dependecies because it tells few classes don't exist, but those classes are part of an external library. (specifically this one). But I have it in the dependencies, so I don't know what more to do.
<dependency>
<groupId>com.github.tdesjardins</groupId>
<artifactId>gwt-ol3</artifactId>
<version>3.0.0</version>
</dependency>
Also in eclipse I had to manually add the jars to my project, so that was why it worked there and not in the command line. So I would also like to ask how to tell eclipse to get those jars and include them to the project, because otherwise eclipse is missing those dependencies and displays many errors.
First I had a problem with <moduleName> in my pom.xml was missing com.company.project prefix before the actual module name.
Then I had errors in my Java files, which was caused by RELEASE version of GWT-OpenLayers 3 library missing some of the features that I previously used by building the JAR from the GitHub repository.

Intellij Idea not finding jar

I have a single java file to compile. It uses javax.servlet-api-3.1.0.jar. I added it to maven with mvn-install and it says it built successfully. However, in Intellij it still throws errors during compilation saying:
package javax.servlet does not exist.
This was after restarting it.
Am I missing anything with adding this jar to my program?
Thanks!
You need a pom.xml file in order to build a maven based project. In short, a pom.xml file is used to tell maven how exactly to build your project, and what dependencies it requires. I'd strongly recommend reading the quickstart guide for maven here

GWT maven project compiles and run from maven but don't compile and run in eclipse

I have multi module maven project, that is build with gwt as a main web framework. Here is github repo.
Everythink works as it should as I supose. I haven't got anything wrong.
Unfortunatelly the problems occur when I try to import this project into eclipse (as maven project). I can not compile this project (using RMB on project in Package Explorer -> Google -> GWT Compile).
I am getting an error:
Loading inherited module 'src.main.resources.pl.derp.parent'
Loading inherited module 'pl.derp.shared'
[ERROR] Unable to find 'pl/derp/shared.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
When I tried to RMB on Project name in Package Explorer -> Run -> Run as Web application (GWT Super Dev Mode)
I've got:
Working directory does not exist: /home/danielo/eclipseGwt/gwt_2.7.0_maven_eclipse/web/src/main/webapp
I've added modules to build path.
I've followed this instruction
I think, that I've done everything to make it work, but still can make it work.
I think the problem is in packages name, and the way they are treated by maven and eclipse. They are treated in diferent ways.
Maven easily find every class (f.e.: package pl.derp.web;) needed and compile. The eclipse is trying to find them by f.e.: src.main.java.pl.derp.web but can't found it.
Really I don't know how to resolve this issue?
I am not sure witch package name patter is better (src.main.java.pl.derp.server or pl.derp.server)- for me the shorter is better.
To run this project in maven (it is well described here):
mvn clean install
mvn tomcat7:run-war-only
and in second shell:
mvn gwt:run -pl web
And in Eclipse I think I am running built in Jetty server
Please give me some help.
You apparently have a single Eclipse project, with server, shared, and web declared as source directories. When using M2Eclipse, you should have 3 projects, each with their src/{main,test}/{java,resources} declared as source directories. At a minimum, without M2Eclipse, the source directories must be the src/{main,test}/{java,resources}, whether you have 1 or 3 projects.
This is why Eclipse looks for src.main.java.pl.derp.server instead of pl.derp.server, and why GWT fails too (classpath is similarly wrong).

Categories

Resources