• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with javax.servlet

 
Greenhorn
Posts: 7
IntelliJ IDE Angular Framework Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I have a problem with javax.servlet. A part of my dependencie tree lookes like

[INFO] +- io.micrometer:micrometer-registry-prometheus:jar:1.1.5:runtime
[INFO] |  \- io.prometheus:simpleclient_common:jar:0.5.0:runtime
[INFO] |     \- io.prometheus:simpleclient:jar:0.6.0:runtime
[INFO] +- io.dropwizard.metrics:metrics-core:jar:4.1.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-undertow:jar:2.1.6.RELEASE:compile
[INFO] |  +- io.undertow:undertow-core:jar:2.0.21.Final:compile
[INFO] |  |  +- org.jboss.xnio:xnio-api:jar:3.3.8.Final:compile
[INFO] |  |  \- org.jboss.xnio:xnio-nio:jar:3.3.8.Final:runtime
[INFO] |  +- io.undertow:undertow-servlet:jar:2.0.21.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.2.Final:compile
[INFO] |  +- io.undertow:undertow-websockets-jsr:jar:2.0.21.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.4.Final:compile
[INFO] |  +- javax.servlet:javax.servlet-api:jar:4.0.1:compile
[INFO] |  \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] \- org.springframework.boot:spring-boot-devtools:jar:2.1.6.RELEASE:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS


The main thing here is that you can see that the javax.servlet is in the tree


In the pom I defined a java.version.



The fact is that I have installed java 11 on my new laptop and of course in the pom I first used version 11.

When I build with version 11 I get the error shown here under. This is of course a part of the messages

------------------------------------------------------------------------------------------------------------------
  • Information:java: Hibernate JPA 2 Static-Metamodel Generator 5.3.10.Final
    Information:java: Errors occurred while compiling module 'sponsor'
    Information:javac 11.0.5 was used to compile java sources
    Information:Module "sponsor" was fully rebuilt due to project configuration/dependencies changes
    Information:5-2-2020 19:48 - Build completed with 18 errors and 10 warnings in 5 s 304 ms
    Warning:java: Supported source version 'RELEASE_6' from annotation processor 'net.java.dev.hickory.prism.internal.PrismGenerator' less than -source '11'
    D:\Projecten\sponsor\src\main\java\eu\inchange\sponsor\security\jwt\JWTFilter.java
    Error:(19, 8) java: cannot access javax.servlet.Filter
     class file for javax.servlet.Filter not found
    Error:(21, 25) java: cannot access javax.servlet.Filter
     class file for javax.servlet.Filter not found
    Error:(8, 21) java: package javax.servlet does not exist
    Error:(9, 21) java: package javax.servlet does not exist
    Error:(10, 21) java: package javax.servlet does not exist
    Error:(11, 21) java: package javax.servlet does not exist
    Error:(12, 26) java: package javax.servlet.http does not exist

  • ------------------------------------------------------------------------------------------------------------------

    The only thing I have to change to make the project build is changing java.version from 11 to 1.8 in the pom

    Why does java 11 not see the javax.servlet in de dependency tree??? I can't stand that I can't figure out what causes the problem. I hope someone knows.


    Greetings,
    Jan
     
    Sheriff
    Posts: 7125
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Your images don't work because they point to file on your local system.  You want attachments (see the Attachments tab in the reply page).

    But in general, don't post images of text.  Instead, copy and paste them into the reply and UseCodeTags (that's a link).  Using an image for displaying your dependency tree is probably okay.
     
    Saloon Keeper
    Posts: 27762
    196
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You have a line in boldface and yes, it's important:


    In Maven, the scope you want for javax.servlet-api is provided. The default scope (compile) both references a resource and copies it into the artefact that the POM produces (WAR, JAR, whatever). A scope of "provided" says tha the build process can reference the library, but doesn't copy it into the product. For the JEE jars, those libraries are part of the server itself and will be added by the server to the application classpath automatically. So if you provide your own, there are conflicts and it can really mess things up.
     
    Jan Dales
    Greenhorn
    Posts: 7
    IntelliJ IDE Angular Framework Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you for the information. I thought it was something like this.

    A few weeks ago I ran into this issue for the first time. As a newbee to Java my thoughts were that when the javax.servlet couldn't be found I have to download it so Java could find it. Now, it's using the javax.servlet-api-4.0.0-b01.jar who is in the default download folder op my laptop.
    When I rename this file I also get the message.

    But because of this stupid action my dependency tree messed up. How do I repair this. My goal is that the local javax.servlet will not be used anymore and I have the right javax.servlet version "on board" in my project.

    Is there a clear solution for this. I have experience with programming for years in an IBM environment and MS Dynamics NAV. The java language is not the most difficult, but to me the environment is.

    Kind regards,
    Jan
     
    Saloon Keeper
    Posts: 15510
    363
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jan Dales wrote:Now, it's using the javax.servlet-api-4.0.0-b01.jar who is in the default download folder op my laptop.


    How? What did you do to get Maven to pick up that file as a dependency? Just downloading it shouldn't cause any problems. Did you configure a repository? Did you change the class path?
     
    Jan Dales
    Greenhorn
    Posts: 7
    IntelliJ IDE Angular Framework Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Stephan,

    I tried so many things to make the project build again, that I unfortenately can't tell you which specific action causes this problem. I'm sorry.
    But this mistake is also a new lesson learned...

    At this point I want to focus on recovery instead of finding the cause of the problem.

    I tried an exlusion in the pom, but that didn't work.

    Hopefully someone on the forum has an idea in which direction to look for a solution.

     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15510
    363
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Finding the cause of the problem IS the road to recovery. Trying to patch the problem with exclusions is not only not gonna work, it's also going to lead to more problems down the road.

    Please post your entire POM, your Maven settings.xml and your CLASSPATH environment variable. Also post the output of 'mvn -v'. Make sure to censor sensitive data from settings.xml.

    By the way, is one of the solutions you tried to add the dependency to Java's ext folder? If so, remove it from there.
     
    Tim Holloway
    Saloon Keeper
    Posts: 27762
    196
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Confusing as the Java world can be, I'd still recommend it over C/C++ or Python, when it comes to comprehensibility.

    I suspect that you are attempting to manually copy jar files into your project. Maven doesn't want you to do that. If you need a jar, you should declare it as a dependency in the POM. When you use maven to generate the war file, Maven will look at those dependencies and check its local cache ($HOME/.m2/repository) to see if there's a copy there. If not, Maven will download a copy from upstream sources - which by default is the Internet, although you can also have a site-wide local repository if you like.

    As I said before, you should not have an actual copy of servlet-api.jar in your WAR, because that library is provided by your webapp server. It may exist as an obviously-visible resource (for example TOMCAT_HOME/lib/serblet-api.jar) or on some webservers they have a monster library with many JEE components in it, including servlet-api. The servlet implementation, incidentally should never be included in your WAR. It's not only part of the server, but unlike servlet-api, which declares the standard, servlet implementations are very specific to the brand and version of the webapp server that uses them. So aside from everything else, if you had to include the servlet implementation in a WAR, it would totally invalidate "write once/run anywhere". Only the servlet API is portable.

    So, in short, there should be 2 servlet api jars on your system. One in the Maven cache, referenced for compiling, but not copied into the WAR (again, scope is "provided"). One in the webapp server, assuming you're running webapps locally. Maven does not reference that one at all. And while I said "2" servlet api jars, of course, if you have projects referencing different versions of servlet-api, the Maven cache will end up with one of each version.
     
    Jan Dales
    Greenhorn
    Posts: 7
    IntelliJ IDE Angular Framework Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Problem solved!!!

    The problem was in the IDE, IntelliJ.

    The code compiled when I used "mvn clean install", so it couldn't be a problem of maven and, in my humble opinion, it had to be something in the IDE. We, a fellow java programmer, started with "mvn --version" this gives the following result

    D:\Projecten\sponsor>mvn --version
    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
    Maven home: C:\Program Files\Java\apache-maven-3.6.3\bin\..
    Java version: 11, vendor: Oracle Corporation, runtime: C:\Program Files\Java\openjdk-11-28\jdk-11
    Default locale: nl_NL, platform encoding: Cp1252
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

    When we looked in IntelliJ we found in the settings (Ctrl+Alt+S) > Build, Execution, Deployment > Build Tools > Maven the setting for "Maven home directory".



    As you can see, the Bundled Maven is divergent because of the version number. Version 3.6.3 via mvn -v and 3.6.1 in the settings.

    We changed the value in "Maven home directory" to "C:/Program Files/Java/apache-maven-3.6.3".

    After that we tried to build again and the result was that it build without any problem. Besides that, all the errors in the Idea, bases on the missing javax.servlet, has disappeared.

    So in the end the problem turned out not te be as big as I expected, fortunately.

    Last but not least, I want to thank Stephan and Tim for their support.
     
    Tim Holloway
    Saloon Keeper
    Posts: 27762
    196
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I don't think that the version difference in Maven was the main problem, but whatever the original issue was, you seem to have dislodged it, and so all's well that ends well!

    IDEs can mess around with secondary programs like Maven and Tomcat, so one good strategy when you have bizarre problems is to simplify by removing the IDE from the equation. That is. run Maven from the command line (which you'll note is how all my suggestions were illustrated).

    A good way to build a WAR, the whole WAR and nothing but the WAR is to run "mvn clean" followed by "mvn compile war:war". Don't just run "mvn war", because it will take existing files and build the war and so after a clean, the WAR is likely to be (nearly?) empty. You have to tell it to compile explicitly. Higher-level goals do that for you, but they have other effects that you might want to minimize here.

    You can also cross-check what's going into the WAR by looking in the target directory, since the WAR is built then in pre-zipped (exploded) form and then zipped/jarred to produce an actual WAR file.
     
    If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic