Stubborn/irrational java.lang.ClassNotFoundException in weblogic ADF, class in JAR - java

I'm new to ADF/JDeveloper and am struggling with the typical 'class not found' - hopefully there's a trick to this?
Using: JDeveloper 12c and the integrated web logic server.
Situation: A Servlet is registered in web.xml, but the class is in a JAR
<servlet>
<description>..</description>
<servlet-name>ABCHandlerServlet</servlet-name>
<servlet-class>com.mine.ControlServlet</servlet-class>
<init-param>
<param-name>licenseKey</param-name>
<param-value>123</param-value>
</init-param>
</servlet>
...
<servlet-mapping>
<servlet-name>ABCHandlerServlet</servlet-name>
<url-pattern>/servlet/GaugeServlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ABCHandlerServlet</servlet-name>
<url-pattern>/mapproxy/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>resources</servlet-name>
<url-pattern>/bi/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ABCHandlerServlet</servlet-name>
<url-pattern>*.ABC</url-pattern>
</servlet-mapping>
com.mine.ControlServlet, which it reports at deployment cannot be found, is in a JAR file.
The JAR file is under
ViewController/Application Sources/META-INF/lib/myjar.jar
I've triple checked that the class is inside that JAR.
I've also tried adding that JAR to the project classpath, although that doesn't seem necessary (didn't make a difference anyway).
FWIW the JAR/Servlet has been used many times in a non ADF environment, so I doubt that the problem is within the JAR.

Removing the JAR from Project Properties->Libraries and Classpath and then readding it fixed the problem.
Time, wasted.
Thanks though to florinmarcus, 1up.

The library might not be packaged in your WAR. Adding the library to ViewControler libraries is half of the story. You may want to check if your WAR deployment profile packages the library too:
Right-Click on ViewController -> Project Properties -> Deployment -> Select the existing Web module in the right -> Edit (icon) -> WEB-INF/lib -> Contributors -> Make sure the library is is checked as part of the deployment.
You can double-check the WAR contents by Right-Click View Controller > Project Properties -> Select the Web Module -> Deploy to WAR.

Related

Java+Tomcat: Continuing development with deployed WAR file (without source code on hand)

I have a compiled war file that I downloaded from remote server. I could run the application locally. The problem is that I don't have a source code and all java files are already compiled .class files.
Now I want to add some new functionality to the existing project. The application is old and it uses web.xml file to declare servlets. E.g:
<servlet>
<servlet-name>ServletOne</servlet-name>
<servlet-class>path.to.ServletOne</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletTwo</servlet-name>
<servlet-class>path.to.ServletTwo</servlet-class>
</servlet>
...
I tried to add a new servlet path in web.xml file like:
<servlet>
<servlet-name>ServletOne</servlet-name>
<servlet-class>path.to.ServletOne</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletTwo</servlet-name>
<servlet-class>path.to.ServletTwo</servlet-class>
</servlet>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>path.to.MyServlet</servlet-class>
</servlet>
...
Then I added a new .java file under path.to.MyServlet and copy- pasted all the code from another (compiled) servlet into my new servlet class (I can see the content of .class files, because there is such a functionality in the IDE I'm using, but those classes are in read-only mode. However I cannot compile MyServlet file (cannot convert MyServlet.java to MyServlet.class. Because the rest of the classes are already compiled (.class format, not .java) and all the import codes are not working (MyServlet cannot see other files).
Here is one of the errors I'm getting when I try javac MyServlet.java:
error: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
Of course I can use something like javac -cp path/to/tomcat/servlet-api.jar MyServlet.java ,but what If I will need to import classes that are already in the project? It will get kinda messy, I suppose...
What is the most organic way of continuing development without having the source code?
What I was thinking is building a separate Spring Boot application, however it will be in a different port and there is a requirement of having one time authentification (Meaning, I cannot ask a user to login again when he/she switches between the applications).
I'm using java-8 and the application is deployed on tomcat-7 (If it's helpful)
If you’re planning to make more changes ongoing, and if decompiling the classes is really permissible in your situation, I think the simplest solution is to create a new project, decompile all of the existing classes, and add them to the new project.
If it’s a one-time change, you can unzip the war file, add the unzipped WEB-INF/classes directory to the classpath for the new file you are compiling (for example, javac -cp path/to/tomcat/servlet-api.jar:path/to/unzipped-warfile/WEB-INF/classes MyServlet.java), then add the new compiled class to WEB-INF/classes and repackage into a war file.

How to find my servlet for web.xml?

I am using wildfly, JBOSS
And I made a Servlet...called ServletImg
My folder structure looks like this:
WebContent/WEB-INF/classes/ServletImg.java
Now i am trying to add him into the web.xml file...like this:
<servlet>
<servlet-name>ServletImg</servlet-name>
<servlet-class>ServletImg</servlet-class> <!-- Here is the problem -->
</servlet>
<servlet-mapping>
<servlet-name>ServletImg</servlet-name>
<url-pattern>/ServletImg</url-pattern>
</servlet-mapping>
Error msg:
servlet.class must be valid fully qualified class name
Any suggestions on resolving the issue?
The point is, everything you need to know is in the question:
Use a fully qualified name.
To solve your problem, all you need to do is:
Create a package to put your servlet in,
Use the name my.package.ServletImg in the web.xml.
It isn't a good practice to put Java classes in the default package, and can be confusing sometimes to servers, as you just faced it
The problem is very clearly given in the error that you've mentioned.
You need to mention the Servlet class name with the full package structure.
For example, check this!
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>examples.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
Observe that the tag < servlet-class> is a fully qualified Class name, that includes the package in which the class has been declared.
Create .java classes in src folder not in WebContent/WEB-INF/classes/
and next if you are creating java dynamic web project then select Dynamic Web module version 2.5 so that you can find web.xml file in Path /ProjectName/WebContent/WEB-INF/web.xml

Spring MVC base/root URL is the same with war name

I created a basic rest service using Spring MVC with xml config. My app name is: myservice. When i create a war from it, I receive a war named myervice-1.0.0. In conclusion, I have to access my application through http://localhost:8080/myservice-1.0.0/resource. I'd like to be just 'myservice', like project name. What can I do? Thanks a lot. I'm using tomcat + gradle.
web.xml:
<servlet>
<servlet-name>webappservice</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webappservice</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
You can rename the war name. If you are using maven as build tool. Then you can use below solution.
<build>
<finalName>myservice</finalName>
. . .
</build>
It will better if you can share some configuration details like pom.xml,web.xml etc.
If you double click on the server definition in STS, you will see a "modules" tab. From there, you can edit the "Path" and set it to whatever you want. When you select "Run on Server", STS has to define a context path and simply defaults it to last element of the default package. If I recall correctly, by default Tomcat uses the file name name of the zipped or exploded .war. In either case, you can over-ride it.
see more about it here

Spring template MVC project fail to run out of box, STS2.8.1 on linux 64bit

Unable to run spring template project on STS. Where to check it?
There is a spring template with STS. But, it failed on an old STS, and failed on a freshly installed STS-2.8.1, nothing changed but give a project name and top package to start the project.
No mapping found for HTTP request with URI [/you/home.htm] in DispatcherServlet with name 'appServlet'
And it seems all configured in web.xml, and servlet-context.xml :
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Can we believe the contextConfigLocation setting must be ok? Why it can not get the handler?
The correct url for the Home controller is <server>/<applicationName>/ (not `.../home.html").
So for example it the Projects name is "test" and you use a Tomcat, then the urls is: http://localhost:8080/test/
And I fond a second problem, but I can not reproduce it
I have tryed the "Spring MVC Template" my own and get stucked with exaxtly the same output.
I was reading the code and configuration again and again, and did not find any mistake, because there is no.
After I modified the HomeController
public HomeController() {
logger.info("init home");
}
It starts suddenly working! -- So I think it was a Eclipse referesh Problem. (Just try to clean and republish the project)
You may try this:
First stop the server if it is running.
Expand src Tree and
Select src/main/webapp
Right click it
From Popup Menu select Build Path
Select 'Use As Source Folder' option
Now try to run the project again

JBoss error report: HTTP Status 404 - Servlet is not available

I'm trying to create a very basic web project called "web" using MyEclipse and JBoss 5 as an application server. I've created one package called "pages" and inside it one servlet called "UserInterface". The problem is when I deploy the project and run the server I always get the error report: HTTP Status 404 - Servlet is not available.
This is a part of my web.xml:
<servlet>
<servlet-name>UserInterface</servlet-name>
<servlet-class>pages.UserInterface</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserInterface</servlet-name>
<url-pattern>/UserInterface</url-pattern>
</servlet-mapping>
and I'm navigating in the browser to: http://localhost:8080/web/UserInterface
What am I doing wrong here?
Thanks
404 means the URL you're trying to access does not point to an existing resource on your server. Check the address again, maybe the "web" (from http://localhost:8080/web/UserInterface) part is not correct because maybe the app is not deployed with that name. By default the app context name is derrived from the filename of the ".war" file such as if your file is "myApp.war", your app should be available at http://localhost:8080/myApp
Also, if you're actually deploying your war inside an .ear file that that ear file will contain an application.xml aplpication descriptor which can map your app file to a specific context, no-matter what the .war filename is, something like:
<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>theApp</context-root>
</web>
</module>
Finally, if you're autodeploying from Eclipse with the JBoss Eclipse connector, sometimes the thing bugs out and doesn't in fact deploy your app properly (even though the app itself is fine). If that's the case, trying manually deploying the .war to an application server and check it that way.
HTTP Status 404 - Servlet is not available.
The loading of the servlet has failed (if the servlet wasn't properly declared in web.xml or the URL was wrong, then you should instead have seen "404 - Resource not found"). Simply put, the <servlet-class> is wrong or the concrete class file isn't present in /WEB-INF/classes.
I still dont know what was wrong, but I've created another servlet called user, and in the web.xml I've added /servlet before the class and navigated to it in the browser (http://localhost:8080/web/servlet/User) and it worked.
<servlet>
<servlet-name>User</servlet-name>
<servlet-class>pages.User</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>User</servlet-name>
<url-pattern>/servlet/User</url-pattern>
</servlet-mapping>
Thanks everyone for your help!

Categories

Resources