Why?
When use System.out.println in client - nothing is output in console of CodeServer.
Now I'm logging in browser console, but how to log in system console?
p.s. I know that best way for logging in gwt is using com.google.gwt.logging.Logging module. It's also now working with system console.
The super dev mode is basically the same than a production compile (it just does not optimize)
In production (compiled javascript) System.out does not print anything into your java server side process. Your code runs in the Javascript VM and it would need to go over the wire to print to the java console.
If you are running in dev mode you are running inside the JVM that is connected to a plugin inside your browser. This is why System.out works.
I set up a remote logger to solve this problem. This way all the client log statements are sent to the server where the logging still works. You can find instructions here: Setup a remoteLoggingServlet in GWT.
Then you can use normal java util logging.
import java.util.logging.Logger;
private static Logger log = Logger.getLogger("mylogger");
Stack traces are unfortunately in javascript. I haven't figured out how to get proper java ones yet.
Hope this helps!
Not the prettiest of solutions but you can create a native JSNI method like this:
public static native void debug(String text)/*-{
console.debug(text)
}-*/;
Then just call:
debug("text here").
And it should output to the console.
Related
I got a problem using beakpoint. there are many discussed topic regarding my question. but all of them are about java program( where main() is declared) but for servlet program how to use breakpoint? i am using elcipse IDE galileo version.
Either you let Eclipse start the web container in debug mode, and you use the breakpoint exactly like you would do on a standalone application, or you start the container in debug mode from outside of eclipse, and define (and start) a debug configuration in eclipse which connects to the remote debugging session of the container.
The way to start the container in debug mode, and the port to use to connect the debugger to the server, depends on the container. Read its documentation.
Whatever the way you choose, you'll have to use your webapp (using your browser, for example), until a request is sent to your servlet and the line with the breakpoint is executed. At this point, the way to debug is exactly the same way as if you debugged a standalone application.
I have integrated eclipse & TestNG & could able to run one sample Java program which provides the output folder. But while included web driver script it could not run using TestNG, but able to run the same using Java program(two choices it ask while right click on the script to run).
Please le me know where the issue might be.
Thanks,
Amal
As #Chetan said in the comments - you need to attach the #Test annotation to your method.
your method would look something like...
#Test
public void myTest() {
WebDriver driver = new...
}
Also when you import, import TestNG's Test annotation. not jUnit's.
I have a litte web app which works properly when deployed to the App Engine in Eclipse.
However, I get an error when I want to deploy my app to my Tomcat server.
I copied the content of my war folder directly to the default ROOT folder of Tomcat.
Then I run my app on an external server inside Eclipse.
Everything works fine to that point - the app is loaded straight from the browser's cache.
Here comes the problem:
The google chrome development console says "Uncaught ReferenceError: function is not defined" when I click on some features of my app that are realized through JSNI on GWT side.
I understand that the error comes from a JS caller inside external JS code. The caller invokes a GWT client-side method/function (that's why it is not defined in the ext. JS code).
Any suggestions on how to solve this problem?
Do you have any extra modules that require external js files? Some modules require the js files to be included in the war and included in your root .html file. It could be the case that you are using a library that doesn't have the base js functions.
You can add this to your .gwt.xml file to turn on the stack trace.
<set-property name="compiler.stackMode" value="emulated"/>
<set-configuration-property name="compiler.emulatedStack.recordLineNumbers" value="true"/>
<set-configuration-property name="compiler.emulatedStack.recordFileNames" value="true"/>
You could also try the setUncaughtException handler to see exceptions that are being thrown in production mode. With the emulated stack trace turned on you should be able to get a backtrace that has line numbers for your code. It is not as good as development mode but very useful for debugging.
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler()) {
#Override
public void onUncaughtException(Throwable cause) {
logger.log(Level.SEVERE, "OOPS", cause);
}
}
Note Make sure your logger is configured to use something you can access. Like firebug or remote logging servlet.
I currently use tomcat 7 in production and development mode using eclipse. You can configure a tomcat instance of the server in eclipse and use the "Run as WebApplication on External Server". This will allow you to see the exception in development mode.
Also make sure you don't have the ?gwt.codesvr=127.0.0.1:9997 if you are in production mode. This will cause problems too unless you have the development code server running.
I am writing my first GWT and i confess i have no idea how to set up loggers.
I am deploying the application to tomcat and want to be able to set up a logger so that i can log to a file in $catalina.home. Gwt came with logging.properties for a java util style log and log4j.properties; i have looked at documentation for the gwt java util logger and it seems to just write to console so it must be log4j i need?
In the past ive seen org.apache.log4j.Logger used, is this what i want?
Could somebody please point me to somewhere where this is documented?
Thanks.
The documentation is here. You can't use file appenders directly because the GWT code runs as Javascript in the browser (when not in development mode). If you want to log to a file you need to enable remote logging.
If there is a server side part logging works as normal. But then it has not much to do with GWT, except for being in the same project and providing services (via a custom protocol).
What do you want to log? rpc service servlets or client logic?
Log4j is just for java not javascript. So it is intended to log your classes in your /server/ package that will be deployed in your server.
Your /client/ package classes will be translated to javascript and will run in the client browser. So, no Java at all!
You can use log4j "emulated" to javascript with http://code.google.com/p/gwt-log/ which will send your client logs using a RemoteLogger to the server via rpc and then you can log them to a file.
I have an Eclipse plugin (A) which has a dependency on another plugin (B). Plugin B is simply a wrapper around a jar, which contains a native dll, and performs jni functionality.
Given this setup, I have the following code in A's Activator class's start method:
MessageConsole jniConsole = new MessageConsole("Opereffa Output", null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { jniConsole });
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(jniConsole);
MessageConsoleStream stream = jniConsole.newMessageStream();
System.setOut(new PrintStream(stream));
System.setErr(new PrintStream(stream));
When plugin A performs its functionality, any use of System.out actually goes to the console within Eclipse. But native code used by JNI also writes to output stream, which I can't grab.
During development, output from JNI goes to the console of the Eclipse instance which has launched the running instance, which contains the plugins.
So how do I grab the JNI output and display in the console?
You could try using freopen to redirect stdout in exactly the same way as you do in Java, but on the native side. The question is whether this would work if you used it in your own plugin (with a new JNI dll): it may need to be used from within the dll doing the console output, I've no idea of the interaction between streams across DLLs. If stdout refers to a shared stream for the whole process, maybe it would work.
You can't, really. The native DLL uses stdio methods that you can't access from Java. If you write to System.out, the Java runtime eventually uses the same methods but for obvious reasons, changes the System.out have no effect to underlying the C runtime.
There is a hardware solution: Get a second monitor so you can see the terminal in which you started Eclipse all the time.
E.g. Eclipse 2019-06 regularly delegates std::printf(...) and std::cout from JNI code to the Console View
Flushing (=actually printed) is done by fflush(stdout);.