Why isn't my GWT web application running properly? - java

I'm going through the book: GWT in Action. On chapter I'm working through the very first hello world application. It's all in development mode.
My issue is that the label in my .java file is not showing up when I open the URL webpage. There is nothing being displayed versus the Label("Hello World!") appearing.
EDIT: When at the displayed webpage, I pressed F12 in google chrome to see if I could find anything weird. Got the error: Failed to load resource: the server responded with a status of 404 (Not Found)
HelloWorld.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.6.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User" />
<source path="client" />
<entry-point class="com.example.gwt.client.HelloWorld"></entry-point>
</module>
HelloWorld.java
package com.example.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
#Override
public void onModuleLoad() {
RootPanel.get().add(new Label("Hello World!"));
}
}
HelloWorld.html
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>HelloWorld</title>
<script type="text/javascript" language="javascript" src=".nocache.js"></script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
</body>
</html>
My console is displaying this after I run it as a web application:
[WARN] Server class 'org.eclipse.jetty.servlet.listener.ELContextCleaner' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/C:/Users/Qs/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.6.0/gwt-2.6.0/gwt-dev.jar' to the web app classpath for this session
For additional info see: file:/C:/Users/Qs/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.6.0/gwt-2.6.0/doc/helpInfo/webAppClassPath.html

If you don't specify the rename-to in your gwt.xml as shown below then by default GWT places the generated nocache.js under war directory by the name of location of gwt.xml followed by its name as shown in below snapshot.
<module rename-to="xyz">
For more info have a look at gwt-module dtd.
Please have a look Defining a module and Renaming modules
There are two ways to solve this issue:
define rename-to in gwt.xml that is more preferable over second solution
gwt.xml
<module rename-to="hello">
html
<script type="text/javascript" language="javascript" src="hello/hello.nocache.js"></script>
use default way
html
<script type="text/javascript" language="javascript" src="com.example.gwt.HelloWorld/com.example.gwt.HelloWorld.nocache.js"></script>
Here is a snapshot to make it more clear

Change the src attribute of the script tag in HelloWorld.html to
src="com.example.gwt.client.HelloWorld/com.example.gwt.client.HelloWorld.nocache.js"
If that still doesn't work, run the GWT compiler and look at the files it generates to determine the exact name of the *.nocache.js file.

Related

Jira spring application plugin not accessing angular assets folder

I am new to Jira and I have created one application and her I have used atlassian-scanner and also I have included angular project everything is working but when any rest request is getting called from main.js it is not working, not sure what is happening is it not considering assets folder or what please help.
Here is my below code for xml web-resource:
<?xml version="1.0" encoding="UTF-8"?>
<bundles>
<web-resource key="client-resources" name="Client Resources">
<resource name="assets/" type="download" location="client/assets/" />
<resource name="main.js" type="download" location="client/main.js" />
<context>com.ngdemo.client-resources</context>
</web-resource>
</bundles>
and my index.html code as below:
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/jira/plugins/servlet/demo/" />
<meta name="decorator" content="atl.general" />
<meta charset="UTF-8">
<title>Angular Demo</title>
$webResourceManager.requireResourcesForContext("com.ngdemo.client-resources")
</head>
<body>
<app-root></app-root>
</body>
</html>
the url which is wrong it is as below:
http://localhost:2990/jira/plugins/servlet/demo/assets/i18n/en.json
but instead I think it should be as below like main.js:
http://localhost:2990/jira/s/d41d8cd98f00b204e9800998ecf8427e-CDN/-ufur03/713000/b6b48b2829824b869586ac216d119363/1.0.0-SNAPSHOT/_/download/resources/com.demo.ngdemo:client-resources/main.js
http://localhost:2990/jira/s/d41d8cd98f00b204e9800998ecf8427e-CDN/-ufur03/713000/b6b48b2829824b869586ac216d119363/1.0.0-SNAPSHOT/_/download/resources/com.demo.ngdemo:client-resources/assets/i18n/en.json

Spring MVC CSS, fonts, images wont show in index.html page

I'm new to spring framework and I was able to run my index.html from my localhost but all resources won't show. Below is my folder structure
- src/main
- webapp
- resources
- css (All css files)
- fonts (All font files)
- images (All image files)
- js (All js files)
- static
- index.html (my index.html)
- WEB-INF
My index.html page:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>My First Application</title>
<meta name="description" content="overview & stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="/resources/css/bootstrap.min.css" />
<link rel="stylesheet" href="/resources/font-awesome/4.5.0/css/font-awesome.min.css" />
.........
In the "href" I tried changing the directory path multiple times, the page is loading but just a bunch of texts (No css, image, etc)
Do I also need to update my servlet-context.xml or web.xml?
EDIT:
I checked servlet-context.xml and the mapping already exists for resoucres:
<mvc:resources mapping="/static/**" location="/static/" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
I even added:
<resources mapping="/resources/css" location="/resources/css" />
<resources mapping="/resources/fonts" location="/resources/fonts" />
<resources mapping="/resources/images" location="/resources/images" />
but still won't work.
EDIT 2:
When I go to chrome - inspect - console. This is the log:
springmvc:13 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/font-awesome/4.5.0/css/font-awesome.min.css
springmvc:21 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/ace.min.css
springmvc:18 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/fonts.googleapis.com.css
springmvc:26 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/ace-skins.min.css
springmvc:27 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/ace-rtl.min.css
springmvc:36 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/ace-extra.min.js
springmvc:2149 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery-2.1.4.min.js
springmvc:2159 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/bootstrap.min.js
springmvc:2166 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery-ui.custom.min.js
springmvc:2167 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.ui.touch-punch.min.js
springmvc:2168 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.easypiechart.min.js
springmvc:2169 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.sparkline.index.min.js
springmvc:2170 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.flot.min.js
springmvc:2171 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.flot.pie.min.js
springmvc:2172 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.flot.resize.min.js
springmvc:12 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/bootstrap.min.css
springmvc:18 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/fonts.googleapis.com.css
springmvc:13 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/font-awesome/4.5.0/css/font-awesome.min.css
springmvc:21 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/ace.min.css
springmvc:26 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/ace-skins.min.css
springmvc:27 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/css/ace-rtl.min.css
springmvc:36 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/ace-extra.min.js
springmvc:2149 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery-2.1.4.min.js
springmvc:2159 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/bootstrap.min.js
springmvc:2166 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery-ui.custom.min.js
springmvc:2167 GET http://localhost:8080/$%7BpageContext.request.contextPath%7D/resources/js/jquery.ui.touch-punch.min.js
springmvc:2180 Uncaught ReferenceError: jQuery is not defined
at springmvc:2180
Basically, all the lines in my html that has the:
<link rel="stylesheet" href=
Throws an error.
I tried to change the "href" to:
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/ace-skins.min.css" />
But still the same, css, images, etc won't load.
You need to register Resource Handler in spring to serve static content you can do it by XML way as
or
<mvc:resources mapping="/resources/**" location="/resources/" />
Java config
#Configuration
#EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}
you can also add multiple resource location as
.addResourceLocations("/resources/","classpath:/other-resources/");
use commat to delimit the string and you can provide as many resource location as you want!
Enjoy coding!
Try using relative links like below. Also use Thymeleaf's th:href
<link rel="s`tylesheet" type="text/css" media="all"
href="../../../resources/css/styles.css"`
th:href="#{/resources/css/styles.css}" />
See your deployed directory structure and ensure required files are present in said folders (resources)
Remember to change the relative path ../../ to correct level.
If files not being copied to /resources folder then trying putting them in /main/src/webapp/resources

Struts 2 could not find a result for success returned from an action

I'm not a native English speaker, so my apologizes if I made some idiomatic mistake. I'm completely new on Struts2.
I developed a web project that contains 3 JSP pages, a deployment descriptor (web.xml), a struts configuration file (struts.xml) with 2 actions configured inside (an action named index and an action named welcome) and 1 class that implements the action logic for welcome action. When I try the index action it works perfectly but if I call the welcome action in the URL (welcome.action) I get the following error
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
No result defined for action actions.WelcomeAction and result success
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
...
Now I give you more information about the project and environment:
Development Environment
OS: Mac OS X 10.10.3
JRE: 1.8.0_20
IDE: NetBeans 7.4
App Server: GlassFish 4.0
Server Location: localhost:8080
Context Path: /AppStruts2Example
URL Project: http://localhost:8080/AppStruts2Example/
Web Project Development Information
Java EE Version: 7
Struts2 Version: 2.3.15
Code is described below
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true" />
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="index">
<result>/WelcomeFromIndexAction.jsp</result>
</action>
<action name="welcome" class="actions.WelcomeAction">
<result name="success">/WelcomeFromWelcomeAction.jsp</result>
</action>
</package>
</struts>
actions.WelcomeAction.java
package actions;
import com.opensymphony.xwork2.ActionSupport;
public class WelcomeAction extends ActionSupport{
#Override
public String execute(){
System.out.println("Inside of execute method in WelcomeAction.");
System.out.println("Result: " + SUCCESS);
return SUCCESS;
}
}
index.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index JSP</title>
</head>
<body>
<h1>Welcome to index.jsp!</h1>
</body>
</html>
WelcomeFromIndexAction.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index Action</title>
</head>
<body>
<h1>Welcome From Index Action</h1>
<br />
<h3>Current Page: WelcomeFromIndexAction.jsp</h3>
</body>
</html>
WelcomeFromWelcomeAction.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Action</title>
</head>
<body>
<h1>Welcome From Welcome Action</h1>
<br />
<h3>Current Page: WelcomeFromWelcomeAction.jsp</h3>
</body>
</html>
Project works fine when:
I write directly the URL of anyone JSP on the browser
I invoke the index action as you can see below: /index.action or /index -> both redirect me to WelcomeFromIndexAction.jsp
Project fails when:
I invoke the welcome action as you can see below: /welcome.action or /welcome -> both shows me a web page with Struts Problem Report like described above
I thought it could be a problem with GlassFish Server, so I mounted a Debian on a VM and I installed a Tomcat 7 there. My next step was deploy the web application whit "Clean and Build" from NetBeans. It generated me a WAR file that I deployed into Tomcat 7 but I got the same problem. After this disappointing I disabled the Debian VM (Tomcat 7) and I come back to work with GlassFish 4.0
As you can see in WelcomeAction.java, it has a println statement within execute method. When I invoke welcome action on the browser, I can see that Struts effectively calls that method, the lines are printed on the output and after this call, when Struts2 has to process the Result then show me the error. This confirm me that Struts2 is not finding the result not the action, but I don't know why.
I tried configuring the filter dispatcher with old and new version of filter (FilterDispatcher/StrutsPrepareAndExecuteFilter). With both i get same problem.
I tried configuring the welcome action in struts.xml exactly the same index action (practically by default) but doesn't work too. Only index action run fine.
I tried configuring the welcome action in struts.xml of many many ways, but nothing works.
So, here i am, needing someone help me. I appreciate your answers.
Note: Stackoverflow doesn't allow me post image because i'm new. So, I uploaded an important print screen to my dropbox. https://dl.dropboxusercontent.com/u/101502868/NetBeans%20Struts2%20Error.png
At this print screen you can see the libraries added, execution of execute method, the customized print lines and start of Struts error's.
Thank's.
make entry in struts.xml with custom method in action class named editUser so that control dirctly goes to that perticuler method and handle the result accordingly your logic
<action method="editUser" name="editUser" class="com.action.EditUserAction">
<result name="true">/jsp/editUser.jsp</result>
<result name="false">jsp/index.jsp</result>
</action>
And add custom method in your class instead of override execute method
class EditUserAction extendes ActionSupport{
public String editUser(){
String status = "false";
/**
do your buisness logic
*/
return status;
}
}
After doing same if still the issues is persist then check your configuration carefully
The best way to fix this issue is using Maven to create your project and manage all dependencies you could need. That was the only solution that works to me.
Here is an official guide to create a Struts 2 Web Application using Maven (very simple example): http://struts.apache.org/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html
If you don't have installed Maven is OS X and you don't know how to install it, then follow the next steps to install it:
Download Maven (This example uses Maven 3.3.3. The name of the compressed file is apache-maven-3.3.3-bin.tar.gz): http://maven.apache.org/download.cgi
Unpack the downloaded file (This example assumes that the downloaded file is located in /Users/YourUser/Downloads/). After unpack, a new directory will be created with the same name and path of your maven file downloaded. (In this example: /Users/YourUser/Downloads/apache-maven-3.3.3/)
Open a Terminal
Move your maven directory to your home directory using this command:
mv ~/Downloads/apache-maven-3.3.3/ ~/
Now, you have to edit the file .bash_profile located on your home directory (~/.bash_profile). To edit it, we'll use vi commando as you can see below:
vi ~/.bash_profile
Once opened you must press i to edit it
Now you can edit the file, so you have to write the following:
export JAVA_HOME=$(/usr/libexec/java_home)
export MAVEN=$HOME/apache-maven-3.3.3/bin
Close the terminal and open it again. That's all, Maven should be already installed. Use the following command to verify that Maven is working:
mvn -version
If you see the information about Maven, Java and OS X that you are using it's because Maven is working fine.

Unobtrusive way to combine and compress javascript/css for java/spring/maven applications?

I'd like to add some kind of library, or maven plugin, or 'something' to combine and compress my javascript and css source files.
However, I think this is pretty difficult to do unobtrusively with Java. The Rails people have pretty much solved this problem... it uses the unjoined/uncompressed files for development and then it compresses everything during production. It does this unobtrusively as you don't have to change your html headers or anything like that - it works for both testing and production. This is more or less what I want. Does it even exist in the Java space?
The last thing I want is to comment and uncomment lines of freemarker/html code for development and production - I want everything to be the same. Ideally, I'd want to be able to leave Tomcat running and code my javascript and css, and see my changes instantly - no delays or hickups. I also don't want to have to manually run a command to generate the new javascript every time I make a change... or even have some daemon constantly update it (because then it might not be instantaneous when I'm testing). At the same time, if I'm going to package up my war for production, I want it to use the joined and compressed files instead.
Is this even possible? If so, what tool should I be looking at? I know there are quite a few that do some of this, but they've fallen short on the "unobtrusive" aspect.
Thanks
A solution that has worked for me is using the maven-minify-plugin (groupId is com.samaxes.maven) but only when building for production. Use a build property to specify if you are in development mode or not. Link to plugin
You can then have something like this (I don't know freemarker so I am just pasting some JSP code but I am sure it can easily be converted):
<c:choose>
<c:when test="${developmentMode}">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/custom1.css"/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/custom2.css"/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/another1.css"/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/another2.css"/>"/>
<script type="text/javascript" src="<c:url value="/js/mylibrary.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/more.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/util.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/whatever.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/more.js"/>"></script>
</c:when>
<c:otherwise>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/minified.css"/>"/>
<script type="text/javascript" src="<c:url value="/js/minified.js"/>"></script>
</c:otherwise>
</c:choose>
This way non-minified/combined JS/css is used while in development and the minified css only used when building for production.
EDIT: As requested here is the code to expose Spring-defined beans on the ServletContext:
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<!-- Obviously this can be changed to read from properties file -->
<entry key="developmentMode" value="false" />
</map>
</property>
</bean>
Jawr is a library that provides compression and merge of css/js files. It provides a Tag for the html include statements.
This make it possible to use the same unmodified JSP Page for development (with unmodified css/js) and production (merged and minified).
wro4j seams to similar features.
Using maven-minify-pluginworked for me too.
But I manage to find an even less intrusive way to use it than using conditional tags like c:when, by combining it with the maven-war-plugin.
This code snippet can be used as it is :
First, start by minifying the CSS/JS without using suffix (meaning that the files keep their name)
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.2</version>
<executions>
<execution>
<id>default-minify</id>
<phase>prepare-package</phase>
<configuration>
<charset>UTF-8</charset>
<skipMerge>true</skipMerge> <!-- do not create one big file -->
<nosuffix>true</nosuffix> <!-- do not use suffix like 'min' -->
<cssSourceDir>css</cssSourceDir>
<cssSourceIncludes>
<cssSourceInclude>*.css</cssSourceInclude>
</cssSourceIncludes>
<jsSourceDir>js</jsSourceDir>
<jsSourceIncludes>
<jsSourceInclude>*.js</jsSourceInclude>
</jsSourceIncludes>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
Then, when building the war file, do not overide CSS/JS files (which are already generated in the target by the minify goal)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!-- in order to use minify filed listed bellow -->
<warSourceExcludes>**/*.css, **/*.js</warSourceExcludes>
</configuration>
</plugin>
The built war will then contains the exact same files but compressed.
(this might not be the best way to perform minifying, but it doesn't change anything in development)
Hope this helps...

Linking to a CSS file in JSF?

Within <h:head/> tags I have:
<h:outputStylesheet name="css/common.css" />
This is output as:
<link type="text/css" rel="stylesheet" href="RES_NOT_FOUND" />
The stylesheet is within a folder named css under the webapp folder of my maven war. When I browse to http://localhost:8080/mywar/css/common.css I see the stylesheet.
Any ideas what I'm missing? Thanks in advance.
I followed the directory structure and layout from tip 4 here: http://www.ibm.com/developerworks/java/library/j-jsf2fu1/index.html
Essentially moved the css folder to be under one called resources and then referenced it as:
<h:outputStylesheet library="css" name="common.css" />
Now it seems to work!

Categories

Resources