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
Related
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.
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.
This feels like a really stupid question but I haven't been able to find an answer.
I'm working on a maven project but I do most of my development in eclipse. Is there any way for me to force maven to generate all of my dependencies under target even if there are errors in the code? I set my eclipse project's build path to use the jars under target/dependencies/jars, but calling mvn clean kills them and if there are any errors in my code causing it to not compile mvn package won't create the dependencies but will instead just crash saying BUILD FAILURE. This makes the problem even worse since instead of seeing the actual errors my eclipse will just bombard me with errors everywhere since all of its dependencies just died.
Or maybe the way I'm working with it is just stupid and there's a better way.
Are you using the m2e plugins for Eclipse to process maven projects, or simply importing the projects as general ones?
If the latter, you should use the m2 plugins (simply go to the Eclipse Marketplace and search for Maven), as they interrogate your POM and set up your dependences properly. You can then concentrate on any compile errors in your code.
You should not point to the jars in the target folder for dependent JAR's since this is where the products of building your project are stored. Performing a mvn clean removes this folder.
To use Maven with Eclipse install the m2e plugin in Eclipse. This makes Eclipse understand the structure of Maven projects.
Once installed you can import your Maven project into Eclipse. I use Import... | Existing Maven Projects for this. But you can also directly import form a versioning system.
During the import Eclipse will set up the Eclipse project to use the Maven dependencies to locate the required JAR's. These are taken from the repository as configured with the used Maven installation.
I guess I haven't really had to do this much before because I am running into a strange issue. I am trying to generate a JAR from an existing Java project and then and putting it into a Spring Maven project. I'm sure I'm including it correctly, I have done this many times before with 3rd party JARs that I get (even though its a Maven project I have included some obscure JARs in it and put on buildpath, etc), with my JAR within Eclipse it is showing up fine as if its included, I have a test class that is importing a class from the JAR, instantiating it, etc and its not showing any errors (imports are fine in the IDE, etc), however when I go to do a Maven install I get:
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[11,15] package org.test does not exist
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[21,2] cannot find symbol
I have tried doing a Maven clean but still the same problem, the JAR class I am testing with is this: (was trying a more complex one but then tried this to troubleshoot the issue)
package org.test;
public class something {
public String main () {
return "it is definitely working fine";
}
}
Here is the JAR I generated (with sources visible):
https://docs.google.com/leaf?id=0BzB_xvrbRpbYODQyMjEzOWEtOTdjNS00YjM3LTlkZGUtNjY5NmIwN2RiNTRj&hl=en
I would appreciate any advice as I am rather perplexed and frustrated by this. Thanks
You can include a 'regular' jar in your maven project -just as you described- though it's not a best practice mainly because then you not even lose the functionality of Maven for that jar, but also the whole point of Maven dependency management: you will have to include that jar with your source to make it build.
You can of course also create a Maven artifact for that jar, build it with Maven, install it with Maven and use it as a normal Maven dependency.
You also can create a parent .pom and have your dependency project as a module in it and also your real application (or also your real app can be your parent). See further here.
Since this caused me quite a bit of grief, I figure I should post the solution I found. Apparently you aren't supposed to just include a regular lib JAR in a maven project (although I swear I have done it before and it worked), I found this way to include a local JAR that isn't form a repository from this post:
Can I add jars to maven 2 build classpath without installing them?
I did this and its doing the maven install properly (where version and artifactID are just made up value)
<dependency>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/testjar.jar</systemPath>
</dependency>
I'm expiriencing multiple compilation errors in my project, most of the code is in red, but the strange(or not) thing is that while building the project with maven everything is build successfully and the war is assemled as it should be.
The thing is that auto suggest is not working because code is not compiling. What can I do to fix this?
I'm using eclipse, sorry
UPDATE:
I've tried all suggestions below but none worked
If you are using Eclipse, try Project > clean.. your project.
I don't know why, but Eclipse sometimes just think your project was wrong but it's not. Clean it to entirely build it again.
If it's Eclipse do
Project > Clean
then right click at the parent-most project and do
Maven > Update Project Configuration
Maven > Update Dependencies
I guess you have m2eclipse installed, already.
Use a maven plugin in your IDE
plugin for eclipse
plugin for netbeans
Most likely you have to include external libraries/dependencies in your IDE. It seems when you're building with maven, those dependencies are solved for you.
Some IDE's support Maven projects, try to see if yours does.
You haven't specified what IDE you're using or what the errors are, which makes it pretty hard to give you advice. My guess is that you haven't configured your project (or whatever the equivalent IDE concept is) to tell it the libraries you're using... whereas the Maven build file already contains that information.
EDIT: Okay, so it can't find the right libraries. Options:
Use a Maven plugin and let it manage the project
Edit the project's build path and explicitly tell it which jar files to use.