Maven ERROR: package javax.servlet does not exist [duplicate] - maven

This question already has answers here:
error: package javax.servlet does not exist
(8 answers)
Closed 5 years ago.
I am starting on a legacy project and trying to get it to build using Maven. I'm using Eclipse EE and Tomcat v7.0. The error in the Title line above arises when I run "mvn package" in Terminal. This error is really stumping me because in my pom.xml file I have the following dependency
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
I've also checked in the Properties>Targeted Runtimes and made sure Tomcat v7.0 is the selected runtime. I'm fairly certain it's a problem with my eclipse environment, and would like some suggestions on how to fix it.
EDIT: Here's some additional information. The first output after I run "mvn package" is
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project myProject: Compilation failure: Compilation failure:
This is followed by another strange error that I forgot to include in the original posting. I say it's weird because, like the package javax.servlet, org.apache.catalina should also be included in tomcat
[ERROR] /path/to/Main.java:[7,26] error: package org.apache.catalina does not exist
Also, I think I mixed up the meaning of legacy project, because this isn't an old project. It's just a project that already had a lot of work done on that I'm now helping the original creator with.

The dependency you're missing is probably the Servlet API.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Be sure to import the correct version of the API. For a legacy project, that could be an older version than 2.5.
As mentionned by Grzegorz, you should also use the scope provided since the Servlet API should be provided by your application server (e.g. Tomcat).

Add server runtime to your project.
Example - for Tomcat
1 - right click on your project
2- select build path
3- Go to Libraries tab
4- Add Library
5- Select Server Run time
6- Here you should get the Apache Tomcat
If you don't get Apache Tomcat in here you need to add your server in Project Facets as below -
1- right click on your project
2- Select Project Facets
3- If you dont get options click on the link 'Convert to faceted form'
4- Go to Runtime tab at right side and select your runtime

Related

BiRT latest Runtime as one Maven Dependency for Eclipse

I have a given eclipse maven project which builds to a jar. The pom has one major dependency of BiRT 4.8.0-202010080643 Runtime.
<dependency>
<groupId>com.customer.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.8.0-202010080643</version>
</dependency>
So they pushed the artifact into their own nexus; thats why com.customer.birt.runtime.
I really don't know how the guy did that and which tools he used. Currently I want to update to BiRT 4.9. Replacing the above with the only available:
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>birt-runtime</artifactId>
<version>4.9.0</version>
<type>pom</type>
</dependency
does not go well. Both are totally different constellations from the same big project. How can I make use of the above maven dependency of 4.9 in my simple birt project? I'm building only a service for a desktop application that is hosted and run within an RCP application. I started to list the individual maven deps so that the java compiles which I succeeded to but I still have few unit tests that execute and render ReportEngine and fail because of missing Deps at runtime. This is because the ReportEngine is loading APIs at runtime..
I started to post here once I noticed that I will be declaring the separate deps in pom.xml blindly which is (even if the Unittests pass) very unreliable..
Thank you so much!
M.Abdu
My solution was currently as I put in the comments or yet simpler. I just uploaded manually the birt-runtime jar into nexus using my account within the customer and then put in my pom the exact same unique coordinates groupid:artifactid:version. Plus some other dependencies depending of what my unit tests are asking at runtime, e.g. eclipse.platform, emf.core, w3c, batik.css etc.
I am talking about executing the build using mvn clean verify and resulting a jar file
The jar you get from here
https://search.maven.org/remotecontent?filepath=org/eclipse/birt/birt-runtime/4.9.0/birt-runtime-4.9.0.zip
pom in my case:
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>runtime</artifactId>
<version>4.9.0-20220502</version>
</dependency>

How to solve Maven JSF project : java: package org.primefaces.model.chart does not exist?

this is my first time ever working on JavaEE project. I want to add primefaces so I can use it in a JSF xhtml page. I added the dependency to the Maven file as follows.
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>10.0.0</version>
<scope>compile</scope>
</dependency>
the primefaces got indexed to IntelliJ, and I was able to import it in the java code and on the xhtml page. But when I run WildFly to build and deploy the project I got this error.
jee/bravo/web/beans/ResultsBean.java:6:34
java: package org.primefaces.model.chart does not exist
How to solve this error?
Try removing the line <scope>compile</scope>.
It means it will only be available at compile time, but not at runtime. So everything looks OK in IntelliJ (during compile) but it is still missing on the Application Server like WildFly (during runtime).

After Cleaning a Maven Project from command prompt the server runtime library gets deleted

I am new to maven.
I created a dynamic web project and converted to maven project.
Then from command prompt i cleaned the project using mvn eclipse:clean
I refreshed the project in eclipse
It comes up with an error like JSP Problem : (the server runtime library deleted)
The superclass "javax.servlet.http.HttpServlet" was not found on the
Java Build Path home.jsp
After adding the server runtime library manually the problem solved.
Is there any other way to solve the problem or the problem will not occur at all.
Add below dependency in your pom.xml to avoid the exception:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

Setting javax.xml.ws.Service from JDK, instead of javaee-api with maven

I'm facing with this problem:
The method getPort(QName, Class<T>) in the type Service is not applicable for the arguments (QName, Class<AcessoDadosGeolocalizacao>, WebServiceFeature[])
I used wsimport to generate my clients, but now my maven application is using the class javax.xml.ws.Service from
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>5</version>
<scope>provided</scope>
</dependency>
How can I use the javax.xml.ws.Service from the JDK 6?
I've added the webservices-api to my pom.xml and the problem is gone.
<dependency>
<groupId>javax.xml</groupId>
<artifactId>webservices-api</artifactId>
<version>2.1-b14</version>
</dependency>
If I am adding this entry(webservices-api) ;it is giving run time error while accessing JAXB-API.I found that the JDK6 should be the first in the order of classpath and then maven library.I moved up the JDK6 above the Maven library.Then it worked.
I ran into a similar issue with Eclipse and a Dynamic Web Application. Its not Maven related however googling for that error gets you all of about 7 results in Google as of today's date with about three or more of them being relisting at other websites of the same stack exchange question - so I thought in case others had a similar issue I'd add what helped me. The WAR was set to use JBoss AS5, the VM was set to use Java 6. Because its eclipse and I had already consumed the web service - the error was not occurring on import as the stubs had already been created. I ensured the Java facet was set to use 1.6 (it had been 1.5), I cleaned and built but the error persisted. I then noticed I had a reference on my build path to Java EE 1.5. I removed this, cleaned and built and the error went away.
Hope this helps anyone else faced with the same issue!

ReflectionToStringBuilder errors in Maven Project

Some of my Roo generated .aj files seem to be generating errors as below. I can see commons-lang3-3.1.jar in my Maven Dependencies. I have added this to my pom.xml
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
Failed to execute goal
org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (default) on
project AdminDirect-Model: Compiler errors : [ERROR] error at return
ReflectionToStringBuilder.toString(this,
ToStringStyle.SHORT_PREFIX_STYLE);
I have a multi-module project, and when in STS I try to do a right click and Update Project, I get another annoying error saying "Problems Encountered while setting project description"...although this is probably a separate issue.
As an aside if anyone knows of the correct workflow to create a multi-module spring roo, JSF, JPA application (Model and Web tier under a parent module) that would be greatly appreciated.
I deleted the .m2/repository folder contents and forced a fresh download using Maven Update Project and then forced a refresh of snapshots. Seems to work, jars must have been corrupt?
tomcat server fails to start the server and application in STS

Resources