Wicket 7 with wicketstuff tinymce4 Can't load language - wicket

I'm running Wicket 7.5.0 and wicketstuff-tinymcr with the same version.
Im trying to initialize a tinyMce editor but I get this error:
Failed to load:
http://localhost:8080/mywebapp/wicket/resource/wicket.contrib.tinymce4.TinyMceBehavior/tinymce/langs/sv.js
The tiny script is loaded though:
http://localhost:8080/mywebapp/wicket/resource/wicket.contrib.tinymce4.TinyMceBehavior/tinymce/tinymce-ver-1481290207000.js
This seems to be loaded:
plugins/...
themes/...
./tinymce-ver-1481290207000.js
EDIT
This took care of it:
addCustomSetting("language: \"sv_SE\"");
This are the classes that loads it all:
import wicket.contrib.tinymce4.settings.TinyMCESettings;
public class MyTinyMCESettings extends TinyMCESettings {
public MyTinyMCESettings(TinyMCESettings.Theme theme) {
super(theme);
addCustomSetting("plugins: 'autoresize'");
addCustomSetting("language: \"sv_SE\""); // this works
}
}
The other one:
import org.apache.wicket.Component;
import wicket.contrib.tinymce4.TinyMceBehavior;
import wicket.contrib.tinymce4.settings.TinyMCESettings;
public class MyTinyMceBehavior extends TinyMceBehavior {
public static final String KEY_EVENT = "keyup";
private Component component;
private TinyMCESettings settings;
public MyTinyMceBehavior(TinyMCESettings settings) {
super(settings);
this.settings = settings;
}
#Override
protected String getScript(TinyMCESettings.Mode mode, Collection<Component> components) {
StringBuilder script = new StringBuilder();
script.append(" tinyMCE.init({")
.append(settings.toJavaScript(mode, components))
.append(",onchange_callback : function (ed) {\n" +
" var text = ed.getContent();" +
" $('#" + component.getMarkupId() + "').html(text).trigger('" + KEY_EVENT + "');" +
"}")
.append("});\n");
return script.toString();
}
}

It seems TinyMCESettings detects 'SV' locale and tries to set the language: https://github.com/wicketstuff/core/blob/7db920363a8e0254b33b8deccee95688dd922aa5/tinymce4-parent/tinymce4/src/main/java/wicket/contrib/tinymce4/settings/TinyMCESettings.java#L262
Set it explicitly to null in the settings and it won't try to load it.

Made an edit with code that works.

Related

JsonpRequestBuilder with typed response throws InCompatibleClassChangeError

I have an existing app that I'm adding a "Suggested Products" feature to and I'm having trouble with my JSONP response not being properly transformed to the typed JsArray. I'm hoping someone can give me an idea of what I'm doing wrong?
I have defined my type that will be returned from the server in its own class:
import com.google.gwt.core.client.JavaScriptObject;
public class SuggestedProduct extends JavaScriptObject {
protected SuggestedProduct() {}
public final native String getFormName();
public final native String getImageURL();
}
I have a method that uses the JsonpRequestBuilder to fire off a request to get my JSON.
private void loadSuggestedProducts() {
JsonpRequestBuilder builder = new JsonpRequestBuilder();
builder.requestObject(buildSuggestedProductURL(), new AsyncCallback<JsArray<SuggestedProduct>>() {
public void onFailure(Throwable caught) {
//Handle errors
}
public void onSuccess(JsArray<SuggestedProduct> data) {
if ( data == null) {
//Handle empty data
return;
}
SafeHtmlBuilder sb = new SafeHtmlBuilder();
sb.appendHtmlConstant("<h4>Suggested Products:</h4>");
for (int i=0; i < data.length(); i++) {
SuggestedProduct product = data.get(i); //<- This line throws the exception
sb.appendHtmlConstant("<div class=\"card\">");
sb.appendHtmlConstant("<img class=\"card-img-top\" src=\"" + product.getImageURL() + "\" alt=\"" + product.getFormName() + "\">");
sb.appendHtmlConstant("<div class=\"card-body\">");
sb.appendHtmlConstant("<h5 class=\"card-title\">" + product.getFormName() + "</h5>");
sb.appendHtmlConstant("<a onclick=\"javascript:addItems();\" class=\"cmd-add\">Add <i aria-hidden=\"true\" class=\"fa fa-plus-circle\"></i></a>");
sb.appendHtmlConstant("</div></div>");
}
view.getSuggestedProducts().setInnerSafeHtml(sb.toSafeHtml());
}
});
}
When I try to use a SuggestedProduct from the response, I get an error:
java.lang.IncompatibleClassChangeError: Found interface
com.google.gwt.cor.client.JsArray, but class was expected
I've been following the guide in the GWT documentation. I don't see any difference between what I'm trying and what they say will work. When I debug, it looks as though the returned data is an array of SuggestedProducts, so I'm stumped as to how to proceed. Any help would be appreciated.
After closer inspection I realized my overlay type was missing method bodies for what fields to return from the JSON object they represented. The fix was to include the proper JSNI method definitions.
import com.google.gwt.core.client.JavaScriptObject;
public class SuggestedProduct extends JavaScriptObject {
protected SuggestedProduct() {}
public final native String getFormName() /*-{ return this.formname; }-*/;
public final native String getImageURL() /*-{ return this.imageurl; }-*/;
}

(Eclipse) Syntax Highlighting Plugin, odd issues with getting started on highlighting/validation

I'm making a syntax highlighting plugin for my company. I'm not making a new editor, I am using an eclipse template that uses the Extensions for generic editor.
Disclaimer: I've had a lot of trouble getting XText to work consistently on 3 different machines due to versioning issues, missing files etc. so that's out of the question
org.eclipse.ui.genericeditor.presentationReconcilers
org.eclipse.ui.genericeditor.contentTypes
org.eclipse.ui.genericeditor.hoverProviders
org.eclipse.ui.genericeditor.contentAssistProcessors
org.eclipse.ui.editors
org.eclipse.core.filebuffers.documentSetup
I'm using I'm having some odd issues. Before I get started:
The plugin is detected in Help > About Eclipse > Installation Details > Plugins
Other sample plugins run using the same method i used to run this plugin
Problems:
I'm getting the following error message when placing any content in
the file except <?xml version='1.0'>:
"Content is not allowed in Prolog"
The keywords seem to be highlighted in Blue. As you can see in my
source code, they should be highlighted in red.
Click here to view what my runtime Eclipe editor looks like
when i'm trying to test my syntax rules.
Below are my classes source code.
I'm wondering:
why my keywords are being recognized in syntax coloring but are
invalid commands with that "prolog" error above
Why the prolog errors above are occurring
Why it's validating the file not to my specification or to a different specification
Point me in the right direction
Hope you can help.
Thanks :).
Reconciler Class:
package myplugin;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
public class MyReconciler extends PresentationReconciler {
public MyReconciler() {
// TODO this is logic for .project file to color tags in blue. Replace with your language logic!
MyScanner scanner = new MyScanner(new SyntaxColorProvider());
DefaultDamagerRepairer dr= new DefaultDamagerRepairer(scanner);
this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
}
}
Scanner class:
package myplugin;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.PatternRule;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
public class MyScanner extends BufferedRuleBasedScanner
{
private static String[] misc = {
true",
"false",
"unsigned",
"jump",
"read",
"write",
};
// Tokens
private final IToken KEYWORD_TOKEN;
private List<IRule> basicRules;
public MyScanner(SyntaxColorProvider colorProvider)
{
super(5000);
// CREATE TOKENS
KEYWORD_TOKEN = new Token(new TextAttribute(colorProvider.getColor(SyntaxColorProvider.KEYWORD)));
// CREATE RULES
List rules = new ArrayList<IRule>();
// Add rule for strings and character constants.
rules.add(new SingleLineRule("\"", "\"", STRING_TOKEN, '\\'));
rules.add(new SingleLineRule("'", "'", STRING_TOKEN, '\\'));
// Add word rule for keywords, types, and constants.
WordRule wordRule = new WordRule(new WordDetector(), OTHER_TOKEN);
// Single-line comments
rules.add(new EndOfLineRule("//", STRING_TOKEN));
// Multi-line comments
rules.add(new MultiLineRule("/$", "$/", COMMENT_TOKEN));
// KEYWORDS
for (String misc : misc)
{
wordRule.addWord(misc, KEYWORD_TOKEN);
}
rules.add(wordRule);
IRule[] result= new IRule[rules.size()];
rules.toArray(result);
setRules(result);
}
}
ValidatorDocumentSetupParticipant:
package myplugin;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
public class ValidatorDocumentSetupParticipant implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
private final class DocumentValidator implements IDocumentListener {
private final IFile file;
private IMarker marker;
private DocumentValidator(IFile file) {
this.file = file;
}
#Override
public void documentChanged(DocumentEvent event) {
if (this.marker != null) {
try {
this.marker.delete();
} catch (CoreException e) {
e.printStackTrace();
}
this.marker = null;
}
try (StringReader reader = new StringReader(event.getDocument().get());) {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
documentBuilder.parse(new InputSource(reader));
} catch (Exception ex) {
try {
this.marker = file.createMarker(IMarker.PROBLEM);
this.marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
this.marker.setAttribute(IMarker.MESSAGE, ex.getMessage());
if (ex instanceof SAXParseException) {
SAXParseException saxParseException = (SAXParseException)ex;
int lineNumber = saxParseException.getLineNumber();
int offset = event.getDocument().getLineInformation(lineNumber - 1).getOffset() + saxParseException.getColumnNumber() - 1;
this.marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
this.marker.setAttribute(IMarker.CHAR_START, offset);
this.marker.setAttribute(IMarker.CHAR_END, offset + 1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
#Override
public void documentAboutToBeChanged(DocumentEvent event) {
}
}
#Override
public void setup(IDocument document) {
}
#Override
public void setup(IDocument document, IPath location, LocationKind locationKind) {
if (locationKind == LocationKind.IFILE) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(location);
document.addDocumentListener(new DocumentValidator(file));
}
WordDetector Class:
package myplugin;
import org.eclipse.jface.text.rules.IWordDetector;
public class WordDetector implements IWordDetector
{
public boolean isWordPart(char character) {
return Character.isJavaIdentifierPart(character);
}
public boolean isWordStart(char character) {
return Character.isJavaIdentifierStart(character);
}
}
SyntaxColorProvider Class:
package myplugin;
import java.util.HashMap;
public class SyntaxColorProvider
{
public static final RGB RED = new RGB(200, 0, 0);
public static final RGB GREEN = new RGB(0, 200, 0);
public static final RGB BLUE = new RGB(0, 0, 200);
public static final RGB COMMENT = new RGB(128, 128, 128);
public static final RGB KEYWORD = new RGB(255, 0, 0);
public static final RGB TYPE = new RGB(0, 0, 128);
public static final RGB STRING = new RGB(0, 128, 0);
public static final RGB DEFAULT = new RGB(0, 0, 0);
protected Map fColorTable = new HashMap(10);
/**
* Release all of the color resources held onto by the receiver.
*/
public void dispose()
{
Iterator e = fColorTable.values().iterator();
while (e.hasNext())
((Color) e.next()).dispose();
}
/**
* Return the Color that is stored in the Color table as rgb.
*/
public Color getColor(RGB rgb)
{
Color color = (Color) fColorTable.get(rgb);
if (color == null)
{
color = new Color(Display.getCurrent(), rgb);
fColorTable.put(rgb, color);
}
return color;
}
This looks like the sample editor with some changes - and
documentBuilder.parse(new InputSource(reader));
would be parsing XML, perhaps. It detects improper XML because the prolog is missing. Remove that line from the code, or implement something that flags up and marks issues similarly.
Ok so I've struggled with the same probelm the function that makes this problem is in this line: documentBuilder.parse(new InputSource(reader));, Im in the middle of trying to figure out a text parser by myself.

GWT Generator conflicts with GIN in production mode?

Could you please help me to solve my problem with GWT Generator? Let me explain.
I wish to generate a widget (ListBox with pre-defined values) during the compilation time and I use GWT Generator for that. My solution works as expected in DevMode (when I run the project with mvn gwt:run) and I see the generated listbox on the screen. But when I compile the code and run it in the "Production mode" (using command mvn clean gwt:compile jetty:run-war) I see the dumb listbox with only one item "no-value" instead.
I have one idea about the issue reason. I use GIN in my project. Despite the fact, that I substitute my empty listbox with generated one using Deferred Binding but not GIN Injection, it probably somehow prevents the substitution during the runtime. I tried my listbox on an empty testing project - everything worked as desired in both Dev Mode and Production Mode. But it fails on my working project.
Here is my realisation:
package com.test.generated;
import com.google.gwt.user.client.ui.IsWidget;
public interface IMySelectBox extends IsWidget {}
My empty selectbox:
package com.test.generated;
import com.google.gwt.user.client.ui.ListBox;
/**
* <p>Dumb listbox. It should be replaced with generated file.</p>
*
*/
public class MySelectBox implements IMySelectBox {
#Override
public ListBox asWidget() {
ListBox listBox = new ListBox();
listBox.addItem("no-value","no-value");
return listBox;
}
}
My Generator:
package com.test.generated;
import java.io.PrintWriter;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
/**
* Generates the ListBox and populates it
*
*/
public class SelectBoxGenerator extends Generator {
/**
* {#inheritDoc}
*/
#Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
try {
JClassType classType = context.getTypeOracle().getType(typeName);
return this.getSourceWriter(classType, context, logger);
} catch (NotFoundException e) {
e.printStackTrace();
}
return null;
}
/**
* Generates the source code of the List box.
*/
private String getSourceWriter(JClassType classType, GeneratorContext context, TreeLogger logger) {
final String packageName = classType.getPackage().getName();
final String className = classType.getSimpleSourceName() + "GeneratedImpl";
PrintWriter printWriter = context.tryCreate(logger, packageName, className);
if (printWriter == null) {
// source code has already been generated, abort
return null;
}
ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);
// Extends
composer.setSuperclass(classType.getName());
// Implements interface IMySelectBox
composer.addImplementedInterface(IMySelectBox.class.getSimpleName());
// Imports
composer.addImport(ListBox.class.getName());
// Class body
SourceWriter src = composer.createSourceWriter(context, printWriter);
src.println("#Override");
src.println("public ListBox asWidget() {");
src.println("ListBox sb = new ListBox();");
// ...here I generate values for the selectbox during compilation time.
src.println("return sb;");
src.println("}");
src.commit(logger);
System.out.println("Generating for: " + className);
// return the fully qualifed name of the generated class
return packageName + "." + className;
}
}
This is how I declare the substitution in my module.gwt.xml file:
<generate-with class="com.test.generated.SelectBoxGenerator">
<when-type-assignable class="com.test.generated.IMySelectBox" />
</generate-with>
And I use my generated ListBox as usually:
IMySelectBox mySelectBox = GWT.create(MySelectBox.class);
anyPanel.add(mySelectBox);
As you can see, I don't touch GIN stuff here at all. I use GIN to inject my modules and views. I found Issue 95 in GIN website, probably it is related to my case.
I will be really glad to get any help. Any explanations, hints, workarounds, suggestions are welcome!
Thank you very much in advance!

EXT-GWT (GXT) Display Icon and Text for displayfield in Combobox

Does anyone know how to display an Icon and a Text for the displaying field in ext-gwts combobo? I tried everything.
In the third ComboBox of this example (klick me) there is an icon and the text for the selectable values. This was no problem with the example template. But i want to show the icon and the text for the selected value too. How can i manage this?
I have a Model class for the icon and the text.
public class Language extends DbBaseObjectModel {
private static final long serialVersionUID = 8477520184310335811L;
public Language(String langIcon, String langName) {
setLangIcon(langIcon);
setLangName(langName);
}
public String getLangIcon() {
return get("langIcon");
}
public String getLangName() {
return get("langName");
}
public void setLangIcon(String langIcon) {
set("langIcon", langIcon);
}
public void setLangName(String langName) {
set("langName", langName);
}
}
This is how i initalize the ComboBox. I want to change the displayField "langName".
final ListStore<Language> countries = new ListStore<Language>();
final Language german = new Language("de_DE", "Deutsch");
final Language english = new Language("en_GB", "Englisch");
countries.add(german);
countries.add(english);
final ComboBox<Language> combo = new ComboBox<Language>();
combo.setWidth(100);
combo.setStore(countries);
combo.setDisplayField("langName");
combo.setTemplate(getFlagTemplate());
combo.setTypeAhead(true);
combo.setTriggerAction(TriggerAction.ALL);
combo.setValue(german);
This is the template for the ComboBox two show the selectable values.
private native String getFlagTemplate() /*-{
return [ '<tpl for=".">', '<div class="x-combo-list-item">',
'<img src="resources/images/lang/{langIcon}.png">',
' {langName}</div>', '</tpl>' ].join("");
}-*/;
How can i use an template for the displayField or is there an other possibility?
Thanks!
You need to implement a com.extjs.gxt.ui.client.widget.form.ListModelPropertyEditor.
The com.extjs.gxt.ui.client.widget.form.PropertyEditor#getStringValue returns the string that should be displayed and the com.extjs.gxt.ui.client.widget.form.PropertyEditor#convertStringValue converts the displayed string back into the model.
This isn't a very performant implementation but it works:
public class TemplateModelPropertyEditor<D extends ModelData> extends
ListModelPropertyEditor<D> {
/** Template to render the model. */
private XTemplate template;
#Override
public D convertStringValue(final String value) {
for (final D d : models) {
final String val = getStringValue(d);
if (value.equals(val)) {
return d;
}
}
return null;
}
#Override
public String getStringValue(final D value) {
if (template != null) {
final Element div = DOM.createDiv();
template.overwrite(div, Util.getJsObject(value));
return div.getInnerText();
}
final Object obj = value.get(displayProperty);
if (obj != null) {
return obj.toString();
}
return null;
}
public void setSimpleTemplate(final String html) {
template = XTemplate.create(html);
}
}
Usage:
TemplateModelPropertyEditor<Language> propertyEditor = new TemplateModelPropertyEditor<Language>();
propertyEditor.setSimpleTemplate(getFlagTemplate());
combo.setPropertyEditor(propertyEditor);
which imports?
I added these ones:
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.util.Util;
import com.extjs.gxt.ui.client.widget.form.ListModelPropertyEditor;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
Everthing works fine, but it don't display an icon. When i debug the return div.getInnerText() method throws an error called: Method "getInnerText" with signature "()Ljava/lang/String;" is not applicable on this object.
The created div element looks okay
<DIV><DIV class=x-combo-list-item><IMG src="http://127.0.0.1:8888/resources/images/lang/de_DE.png"> Deutsch</DIV></DIV>

Reading xls file in gwt

I am looking to read xls file using the gwt RPC and when I am using the code which excecuted fine in normal file it is unable to load the file and giving me null pointer exception.
Following is the code
{
{
import com.arosys.readExcel.ReadXLSX;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.Preview.client.GWTReadXL;
import java.io.InputStream;
import com.arosys.customexception.FileNotFoundException;
import com.arosys.logger.LoggerFactory;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* #author Amandeep
*/
public class GWTReadXLImpl extends RemoteServiceServlet implements GWTReadXL
{
private String fileName;
private String[] Header=null;
private String[] RowData=null;
private int sheetindex;
private String sheetname;
private XSSFWorkbook workbook;
private XSSFSheet sheet;
private static Logger logger=null;
public void loadXlsxFile() throws Exception
{
logger.info("inside loadxlsxfile:::"+fileName);
InputStream resourceAsStream =ClassLoader.getSystemClassLoader().getSystemResourceAsStream("c:\\test2.xlsx");
logger.info("resourceAsStream-"+resourceAsStream);
if(resourceAsStream==null)
throw new FileNotFoundException("unable to locate give file");
else
{
try
{
workbook = new XSSFWorkbook(resourceAsStream);
sheet = workbook.getSheetAt(sheetindex);
}
catch (Exception ex)
{
logger.error(ex.getMessage());
}
}
}// end loadxlsxFile
public String getNumberOfColumns() throws Exception
{
int NO_OF_Column=0; XSSFCell cell = null;
loadXlsxFile();
Iterator rowIter = sheet.rowIterator();
XSSFRow firstRow = (XSSFRow) rowIter.next();
Iterator cellIter = firstRow.cellIterator();
while(cellIter.hasNext())
{
cell = (XSSFCell) cellIter.next();
NO_OF_Column++;
}
return NO_OF_Column+"";
}
}
}
I am calling it in client program by this code:
final AsyncCallback<String> callback1 = new AsyncCallback<String>() {
public void onSuccess(String result) {
RootPanel.get().add(new Label("In success"));
if(result==null)
{
RootPanel.get().add(new Label("result is null"));
}
RootPanel.get().add(new Label("result is"+result));
}
public void onFailure(Throwable caught) {
RootPanel.get().add(new Label("In Failure"+caught));
}
};
try{
getService().getNumberOfColumns(callback1);
}catch(Exception e){}
}
Pls tell me how can I resolve this issue as the code runs fine when run through the normal java file.
Why are using using the system classloader, rather than the normal one?
But, If you still want to use then look at this..
As you are using like a web application. In that case, you need to use the ClassLoader which is obtained as follows:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
This one has access to the all classpath paths tied to the webapplication in question and you're not anymore dependent on which parent classloader (a webapp has more than one!) has loaded your class.
Then, on this classloader, you need to just call getResourceAsStream() to get a classpath resource as stream, not the getSystemResourceAsStream() which is dependent on how the webapplication is started. You don't want to be dependent on that as well since you have no control over it at external hosting:
InputStream input = classLoader.getResourceAsStream("filename.extension");
The location of file should in your CLASSPATH.