Maven Dependencies? Doesn't access servlet - 404 Error - java

I have a program that I wrote a couple years ago for a class, and it worked fine. Recently I updated a lot of things - Java, Eclipse, Tomcat, etc. because I haven't been programming in a while. I messed with the dependencies and now I cannot get it to work. It correctly displays the opening jsp, but never makes it to the handling servlet, giving me a 404 error. I think that I must not have the correct dependency for the servlet anymore? I know the program works, so I have not included code for it. The program uses Eclipselink, mySQL, JSP, and Servlets. (Yes, kicking myself for messing with it). These are the dependencies I have. Am I missing one? Have the wrong one? I am not well versed in maven dependencies
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
And my build has:
Apache Tomcat 9
Java jdk 13.1
Maven Dependencies
Thanks for any help you can give.

Well, dang it all. I have been trying to get this working for 2 days. Decided problem was with Tomcat. Downloaded and reinstalled it all. Port errors. Changed to every number in the world. Cleaned server, updated project, etc. Nothing worked. Kept getting port number error. Finally saw where someone said they fixed it by restarting computer. Last ditch effort and for some godforsaken reason, it worked. SOOOOOO frustrating. Thanks for your help anyway. I should know - when in doubt, reboot.

Related

package javax.jws does not exist. I need this package that support jdk1.7

I am trying to run an old maven project, a Website Application from my company, so I can do some changes for an update.
Currently, I'm still making some changes in pom.xml file because some library is not available in the repository. And after some configuration, I've been stuck in this error while I try to run the project using Tomcat Server 7 with JDK 1.7. It is showing that:
error: package javax.jws does not exist
import javax.jws.WebMethod;
error: package javax.jws does not exist
import javax.jws.WebService;
so I search and found this: https://askubuntu.com/a/1149525/1644122
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.0</version>
<type>pom</type>
</dependency>
I have add this library and it went well when I build it using maven.
But, this error appears when I do "run on server" in eclipse.
Unsupported major.minor version 52.0 (unable to load class [com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer])
I believe that the dependency that I add before require JDK 1.8 or above to run. The problem is, I need to to make it run in our tomcat server for a development environtment.
Now, the question is, Is there library that includes package javax.jws and support JDK 1.7?
Or Is there any way to handle this issue?
I'm newbie in Java. This project really driving me crazy :(
Please help me.
I'm not sure if is this the right answer.
But anyway, I add these dependencies, and the errors are not showing anymore.
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>

Strange Exception while working with EWS

I'm creating a project to get emails from exchange server. I'm taking the EWS help to get this job done.
I've the below dependencies added to my pom.xml
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
In my code I'm getting the below import errors.
The import microsoft.exchange.webservices.data.core.ExchangeService
cannot be resolved
The import
microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion
cannot be resolved
And also , I'm getting an error on my package and it reads as below.
The type
microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion
cannot be resolved. It is indirectly referenced from required .class
files
when I opened my decencies tree, I'm surprised to see core.ExchangeService available(please see the below screenshot). But the core.enumeration.misc.ExchangeVersion is missing.
please let me know how can I fix these issues.
Thanks
This seems to be an Eclipse bug, though restarting Eclipse worked great for me, hope this helps somebody else too.
See [http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html][1] for a possible solution, otherwise try the following;
Close the project and reopen it.
Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)
OR
Delete and Re-import the project and if necessary do the above steps again.
OR
If anything not working please try with other IDE it might work.
This bug arises when Eclipse is unable to import the jars properly. Along with the fix mentioned by Maheshwar Ligade above, you may also try removing the import statements from code, saving it, re adding the import code & then saving it again.

Jetty wants Jersey, but I'm not using it

Building a relatively simple jetty app, following the instructions here:
http://www.eclipse.org/jetty/documentation/9.4.x/maven-and-jetty.html
I'm not using Jersey, but mvn jetty:run complains about
Provider com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer not found
My pom.xml does not include any reference to Jersey. In fact, it is quite simple:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.0.1</version>
</dependency>
What is making jetty look for Jersey?
Search all of your dependencies for META-INF/services/javax.servlet.ServletContainerInitializer files.
The one that has the entry for com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer is the one causing you problems.
Look at your project dependencies (aka <project><dependencies>) and your project's configuration of jetty-maven-plugin to see if that <plugin> has any extra dependencies added to it (aka <plugin><dependencies>).
Well, after much machination, and gnashing of teeth, I think I stumbled about the answer. Whilst learning about maven, I was playing with shaded uber-jars. I had compiled one of the packages as an uper-jar, and installed it. When maven put it all together, it added a bit too much and broke my dependencies. Removing the shaded jar for local installation and just using it for distribution worked just fine.

NetBeans Maven: ClassCastException - RestEasy vs Jersey

As my title says, I believe the issue is with classloading, and the fact that my application is trying to cast a jersey-core class to resteasy. Below is the code that triggers it, as well as the error:
java.lang.LinkageError: ClassCastException: attempting to castjar:file:/C:/Program%20Files/NetBeans%207.3/enterprise/modules/ext/rest/jersey-core-1.13.jar!/javax/ws/rs/ext/RuntimeDelegate.classtojar:file:/C:/Documents%20and%20Settings/hwng/My%20Documents/NetBeansProjects/pics-client/branding/target/netbeans_clusters/pics_client/modules/ext/org.jboss.resteasy/jaxrs-api-2.3.5.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.class
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:126)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:96)
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
IRoutesService client = ProxyFactory.create(IRoutesService.class,
"http://localhost:8080/rest/routeservice/");
client.postRoute(txtRouteName.getText());
}
Now, my NetBeans Platform module (maven) has dependency on the following:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.5.Final</version>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>myapp-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
The myapp-api is a jar that is located also on the server and is used to interact with the service. The POM for the myapp-api has the following dependency:
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
All in all, I am not sure why NetBeans is even remotely trying to look at jersey-core when I don't seem to have any reference to it. Any help or advise is appreciated.
I Right Clicked on my RouteTopComponent and looked at the runtime classpath and can clearly see jersey-core in there. How do I get rid of it?
In my case this was a silly mistake of a newbie. I have assumed that pressing F6 in NetBeans (to run) will automatically launch my NetBeans Platform Application (mavenized); however, it wasn't launching what it should. It was launching my TopComponent in a new instance of NetBeans Platform (hence all the Jersey classes loaded).
All I had to do was to actually right click the my-application-app and choose run for it to actually launch my application correctly.
Perhaps this will be useful to anyone who ever makes the same assumption as me and tries to run file directly.

ClassNotFound in Embedded-Jetty and Maven

To do some Surface-Tests I start an embedded Jetty for JUnit-Tests. My tests call some pages from the server. When doing this tests from eclipse everything works fine, the classpath is created by "mvn eclipse:eclipse".
When running those tests with "mvn test" the jsp-Compiler raises a lot of ClassNotFoundExceptions: javax.servlet., javax.servlet.jsp and evene some of my self generated classes. All requests directly answered by servlet work fine.
Doing in my testcases something like System.out.println(HttpServlet.class) works fine, too. So the Jetty-JSP compiler seems to habe some "specials" when compiling.
Anybody knows how to persuade Jetty to compile my JSPs?
There is a maven plugin for that:
http://wiki.eclipse.org/Jetty/Feature/Jetty_Jspc_Maven_Plugin
If you look pom of one jetty module you'll see:
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<scope>provided</scope>
</dependency>
It dependes on own servlet-api classes.
So maybe if you specify dependencies on real servlet-api in your project pom it will work:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
After all the problem seems to have been in mavens dependency-management (or what I allowed maven to do).
I had a real mess of javax-artifacts in my classpath (jsp-2.1, 2.2.3, 2.2.1, servlet 2.5, 3.0, 3.0.glassfish-style). So after I cleaned up dependencies everything works fine. Now I understand why jetty from maven-.build didnn't start. Finally I dont understand why at all jetty came up in eclipse ;)

Categories