HTTP Status 404 will show up when I running tomcat inside Eclipse. And my resource exists. The error will disappear when I restart tomcat for some times. How many times I need to restart tomcat to remove the error is random. And the dialogs of Run on server wizard is random.
Sometimes, I get this error when using welcome-file-list. For some reasons, the welcome-file can be found.
I have used tomcat in Eclipse for some. My overall experience is bad. Maybe some improvements should be made on WTP. For now, I use ANT to deal with Tomcat. And it works well.
Saturday, August 2, 2008
Classpath subtlety when using tomcat inside Eclipse
First, an eclipse dynamic web project only recognized classes produced by source folders configured in Java Build Path->Source and classes in the libraries under WebContent/WEB-INF/lib folder. The locations of source folders and class output folders do not matter if they are inside this project. The count of source folders and output folders also does not matter. By default, the output class folder is build/classes. It does not recognize the jar libraries which are not under WebContent/WEB-INF/lib and class folder configured in Java Build Path->Libraries. For class compilation, it is Ok. ClassNotFound exception will be thrown if you begin to use Run on server.
Wednesday, July 2, 2008
Running the Eclipse 3.4 formatter application
D:\gnu\eclipse\eclipse.exe -application org.eclipse.jdt.core.JavaCodeFormatter -config D:\gnu\jee\workspace\Concurrency\.settings\org.elipse.jdt.core.prefs d:\Foo.java
Thursday, June 12, 2008
variable type checking in C
Put all the files in a directory. Run gcc *.c -o main.exe. The compilation will succeed. The reason is that C does not check type consistency of external variable declaration and reference.
1 one.c
2 main.c
1 one.c
int abc = 1;
2 main.c
#include <stdio.h>
extern float abc;
int main(void) {
printf( "%f", abc );
}
Function type checking in C
Put all the following 3 files in a directory. Run gcc *.c. The compilation will succeed. And running the resulted excecutable file will print I am here, man!. Run g++ *.c The compilation will fail. The reason is that during linking, C only check function names. But C++ check function type.
1. caller.c
2. callee.h
3. callee.c
1. caller.c
#include "callee.h"
int main(void) {
foo();
}
2. callee.h
int foo(void);
3. callee.c
#include
void foo(int v) {
printf( "I am here, man!" );
}
Wednesday, May 14, 2008
Index overflow in Java for loop
The following little code snippet shows the overflow of for loop index in Java.
You may expect that the iteration count is 22. But it is not true. i is 2100000000 after the 22nd iteration. Then 100000000 is added to i(2100000000) again. 2200000000 is bigger than 2147483647. So int overflow will happen. i will become a negative integer. So the loop will continue.
For details of loop index overflow, you can refer to Programming Language Pragmatics.
public class Out {
public static void main(String[] ars) {
for(int i = 0; i <= 2147483647 ; i+=100000000 )
{
System.out.println( i + "\n" );
}
}
}
You may expect that the iteration count is 22. But it is not true. i is 2100000000 after the 22nd iteration. Then 100000000 is added to i(2100000000) again. 2200000000 is bigger than 2147483647. So int overflow will happen. i will become a negative integer. So the loop will continue.
For details of loop index overflow, you can refer to Programming Language Pragmatics.
Friday, May 2, 2008
Genenared methods values and valueOf for Enum
I have recently tried Java Enum when doing software development. The following code is an example:
I found two methods valueOf and values in the Javadoc for my enum code. I did not write these 2 methods. And it's superclass java.lang.Enum<FooType> also does not have these 2 methods. Then I checked JLS 3.0. 8.9 Enums says these 2 methods are automatically generated. It is a little magic. One Java class can has methods which do not exist as source code. Too many magic which do not have a consistent rationale can make a language hard to learn and use.
public Enum FooType {
ABC, DEF;
}
I found two methods valueOf and values in the Javadoc for my enum code. I did not write these 2 methods. And it's superclass java.lang.Enum<FooType> also does not have these 2 methods. Then I checked JLS 3.0. 8.9 Enums says these 2 methods are automatically generated. It is a little magic. One Java class can has methods which do not exist as source code. Too many magic which do not have a consistent rationale can make a language hard to learn and use.
Subscribe to:
Posts (Atom)