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
Related
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
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.
Here are my relevant files.
POM file: http://pastebin.com/ZPTWifys
web.xml file: http://pastebin.com/7kd8Et6Y
JAX-RS resource: http://pastebin.com/ddwDEwNK
I do a mvn clean install - works fine. I point my browser to localhost:8080/firstjersey. I get the "Hello World" index page. Then I try pointing my browser to localhost:8080/firstjersey/resources/test, and I get nothing. I try localhost:8080/resources/test, and get nothing. The problem is that I am simply unable to access my resource. I don't know if it's even being scanned by the servlet container. But everything in my configuration looks right. What's wrong?
I appreciate all help in advance.
Your servlet mapping should include a wildcard:
<servlet-mapping>
<servlet-name>My Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
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
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!