I have created sample web application, packaged it into WAR, then put it into webapps folder into jetty. And it does not work.
Proof, windows from top to bottom:
1) The content of GreetingController.java
2) The compiled file is present inside WAR file in appropriate place
3) The web application is working, it's name is recognized (folder content displayed)
4) Controller is not working and it's name is not recognized
What else to check?
UPDATE
My WAR file: https://www.sendspace.com/file/mb94jt
I think you are missing something in your app. The page you are referring is just a guide to help understand how the framework works. For complete simple examples, please refer to:
https://github.com/javalite/activeweb-bootstrap - this is a simple app with Bootstrap and no database support
https://github.com/javalite/activeweb-lessc - simple app without database, but with Less instead of CSS
https://github.com/javalite/activeweb-simple - simple ActiveWeb + ActiveJDBC webapp (CRUD)
Here is the Getting Started page: http://javalite.io/getting_started_activeweb
hope it helps
Related
I have a spring boot application that runs very well, But after generating a war file so as I can run the application on separate tomcat server not the embedded one, I am unable to access some pages and files. I have rename the generated war file to mywarfile.war .This qusetion has two separate relate issues.
First issue-Access a linked page
Below is the link inside index.html that will lead to a method that will perform some code then leads to all.html
<button class="btn btn-secondary"> View Welding Product Record </button>
Method
#GetMapping("/all")
public String getAllProducts(Model model){
//.....codes
return "all"
}
Everything works fine with embedded tomcat with spring boot, but when click the link with the war file deployed to separated tomcat server it redirects to http://localhost:8080/all and shows below error.
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/all] is not available
Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.65
The mywarfile.war is placed on C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\mywarfile.war
But if I type manual on url http://localhost:8080/mywarfile/all I can access the page. What could be the cause of this. And How can I fix it.
Second issue - Access images
I have a background image in my index.html that can be accessed before generating the war file, But after generating the war file and run it on separate tomcat server I cannot see the image.
Below is the code in index.html
<style>
body{background-image: url('/images/ocean.jpg');}
<style>
This is the structure of how I store the images in my project
\src\main\resources\static\images\ocean.jpg
what could be the cause of this and how can I solve it. Thanks in advance
I m new in Struts2. Creating a hello world program using struts. When I run it got first screen where i put my input but when click on submit button giving following error.
Source of this helloworld example: http://www.tutorialspoint.com/struts_2/index.htm
HTTP Status 404 - /HelloWorldStruts2/hello
type Status report
message /HelloWorldStruts2/hello
description The requested resource (/HelloWorldStruts2/hello) is not available.
Apache Tomcat/6.0.29
Suggest what is the issue?
Got the solution.
In index.jsp there was <form> tag. When I changed it to <s:form> its working fine.
Or change from
<form action="hello">
to
<form action="hello.action">
This is what worked for me, specific to the question. Tomcat 8 was used:
Make sure you have created the classes folder under WebContent\WEB-INF.
In that create the logging.properties file and add the following content to it. (It doesn't matter if the file jumps on its own to Java Resources > Libraries) :-
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = \ java.util.logging.ConsoleHandler
Then in the location of Tomcat's webapps folder delete your HelloWorldStruts2.war file.
Now follow the site's instructions to Export your project to a new HelloWorldStruts2.war file (remember to overwrite the existing .war file with the same name if it's there).
Again, deploy this file by copying it to your Tomcat directory's webapps folder.
In the browser, go to http://localhost:8080/HelloWorldStruts2/index.jsp again, though I'm not sure it will work for sure this time.
But this time, watch the Tomcat server application's verbose output. You will get some kind of exception like this (leave out Warnings for now):
30-Mar-2014 17:39:29.273 SEVERE [localhost-startStop-7] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:213)
at org.apache.struts2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:102)
...
Seeing this, what I did immediately was copy the commons-lang3-x.y.z.jar to the WebContent\WEB-INF\lib folder, and then exported and deployed the project again.
This time, again the page wasn't showing, so I watched the logs and found out that Tomcat did not explicitly clear the contents of the webapps\HelloWorldStruts2 folder.
After deleting both HelloWorldStruts2 and HelloWorldStruts2.war and refreshing the index.jsp page in the browser, my project did work fine!
I am in the process of creating a REST web service in Java Spring. I've successfully loaded STS and the example detailed at :
"This guide walks you through the process of creating a "hello world" RESTful web service with Spring."
http://spring.io/guides/gs/rest-service/
However that tutorial only goes so far.. I want to create a WAR file instead of a self running jar containing a servlet, and deploy that WAR file. I then found this tutorial, and attempted to just modify the first tutorials build.gradle file.
"Converting a Spring Boot JAR Application to a WAR"
http://spring.io/guides/gs/convert-jar-to-war/
It seemed to build just fine into a .war file.. the service is running in my TOMCAT instance's manager.. but I get 404's once I attempt to use the service.
URL 404'd
http://localhost:8080/gs-rest-service-0.1.0/dbgreeting?name=MyName
Do I need to modify the mapping?
DataBaseController.java
#RequestMapping("/dbgreeting")
public #ResponseBody DataBaseGreeter dbgreeting(
#RequestParam(value="name", required=false, defaultValue="World") String name) {
return new DataBaseGreeter(counter.incrementAndGet(),String.format(template, name));
}
Now I have the .war file created according to a blending of things.. and worried I perhaps missed something.
I've since discovered XAMPP on OSX doesn't contain a webapp/ folder, which has forced me to load Bitnami's Tomcat stack instead. Do people generally switch between XAMPP and other stacks based on this? or did I miss something to get webapp folder created in XAMPP?
A WAR is just a JAR with special properites. It needs to have a WEB-INF, under which you need a web.xml to describe your deployment, any app server dependentXML configuration files, and usually a lib, classes, and other odds and ends.
The easiest way would be to use Maven to create your WAR. I think you should be able to simply change the project type in the pom.xml from JAR to WAR. The tutorial you followed seems to use Gradle, which in turn uses Maven I believe, so you should have one there somewhere. Other than that, google for tutorials on how to construct a WAR. I don't believe that Tomcat requires any special deployment descriptors, so you should only need the web
.xml.
(Answer from OP moved from question to here)
Boy I feel really dumb.. Found there was more to the tutorial after changing the gradle instructions.. including the very needed Auto Configuration that supercedes/replaces the need for a web.xml
Solution
Initialize the servlet
Previously, the application contained a public static void main() method which the spring-boot-gradle-plugin was configured to run when using the java -jar command.
By converting this into a WAR file with no XML files, you need a different signal to the servlet container on how to launch the application.
src/main/java/hello/HelloWebXml.java
package hello;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.SpringBootServletInitializer;
public class HelloWebXml extends SpringBootServletInitializer {
#Override
protected void configure(SpringApplicationBuilder application) {
application.sources(Application.class);
}
}
Will give credit to the first answer, but you both were correct that the web.xml (or what Spring-Boot uses to replace it) was needed.
I would expect to see some INFO output when a spring boot application starts so some ideas are:
Try a regular tomcat instance
Download and extract the zip distribution.
Start tomcat with bin/startup.sh
Copy your war to the webapps directory
Check the logs... hope to see some evidence of spring starting up
Manually inspect the war file
Unzip your war file
Expect to see WEB-INF/web.xml
So I have an Axis2 web service (called "ReleaseService"), which requires a properties file to work correctly. I've deployed axis2 into Tomcat7 on RHEL6 and have a structure like this:
tomcat/webapps/axis2
+ axis2-web, META-INF, org
+ WEB-INF
+ + classes, conf, lib, modules
+ + services
+ + + ReleaseService
+ + + + com, lib, META-INF
Thinking about Java, I would expect the working directory to be tomcat/webapps/axis2/WEB-INF/services/ReleaseService, because it contains a lib folder and the root folder for my binaries.
So I put my properties file in there and tried to access it via
File configFile = new File("releaseservice.properties");
which apparently doesn't work. I've looked for hours but couldn't find a post or documentation snippet, which tells me where the working directory is. I found this, but a system property is no option for me, because I want to keep the deployment simple.
Found out, that the working directory is my tomcat/bin folder, which is the root of the Tomcat Java process.
Bonus question: How can I find out my service directory inside my web service? Does Axis2 provide any helpers to find out which is the folder for the service?
Making assumptions about the current working directory in application code deployed in a Java EE container is not recommended. In addition, you are making the assumption that when the WAR is deployed, releaseservice.properties will exist as a file, i.e. that the container explodes the WAR. This is true for Tomcat, but may not be the case on other servers.
Axis2 creates a distinct class loader for every deployed service. This means that you can access your property file by looking it up as a resource:
MyService.class.getResourceAsStream("/releaseservice.properties")
Replace MyService with the actual class implementing your service, or any other class loaded from WEB-INF/services/ReleaseService.
Apparently the working directory is the tomcat/bin folder. Even though it seems like there is a dedicated application running inside tomcat, it's all the same Java process.
Found it out by adding the following debug code:
File test = new File("abc.txt");
System.out.println(test.getAbsolutePath());
Which returned /opt/tomcat/bin
I have an Eclipse Java project, and I added a "folder" off of the root called "webfiles". I then proceeded to create a file called form.html. Once I run the project locally or publish it, I cannot reach the .html file. I get a Not_Found error.
Is it possible in Google App Engine to use HTML files (other than index.html) and where do I have to place them in the project to access them by a browser? What path should I use in the browser.
You need to add include path="/**.html" " in your static files definition in appengine-web.xml else html files other than index.html would not even be uploaded.
If you have /war/webfiles/form.html in your project than path to acces it from browser:
http://your_app_name.appspot.com/webfiles/form.html
To make reference from other jsp pages use:
link to form