Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help: netbeans packages and directory structure SNAFU

1 view
Skip to first unread message

javac

unread,
Jun 9, 2004, 5:33:39 AM6/9/04
to
how does the directory structure effect netbeans? i alternate between
the terminal (pico etc) and netbeans. basically, how do i get this to
compile? it compiled fine before i added the first line: "package
servlet.javac"

FWIW, this is in reference to <http://www.myjavaserver.com/~javac/>
and trying to get this servlet to to work there..

--------netbeans-----------------------
Exception in thread "main" java.lang.NoClassDefFoundError:
WelcomeServlet3 (wrong name:
servlet/javac/WelcomeServlet3)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:605)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:290)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:279)
at java.lang.ClassLoader.loadClass(ClassLoader.java:236)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:303)
------------/netbeans------------------
------------WelcomeServlet3-------------
package servlet.javac;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WelcomeServlet3 extends HttpServlet {

// process "post" request from client
protected void doPost( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException {
String firstName = request.getParameter( "firstname" );

response.setContentType( "text/html" );
PrintWriter out = response.getWriter();

// send XHTML page to client

// start XHTML document
out.println( "<?xml version = \"1.0\"?>" );

out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " +
"XHTML 1.0 Strict//EN\" \"http://www.w3.org" +
"/TR/xhtml1/DTD/xhtml1-strict.dtd\">" );

out.println(
"<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

// head section of document
out.println( "<head>" );
out.println(
"<title>Processing post requests with data</title>" );
out.println( "</head>" );

// body section of document
out.println( "<body>" );
out.println( "<h1>Hello " + firstName + ",<br />" );
out.println( "Welcome to Servlets!</h1>" );
out.println( "</body>" );

// end XHTML document
out.println( "</html>" );
out.close(); // close stream to complete the page
}//doPost
}//WelcomeServlet3
------------/WelcomeServlet3-------------

thanks,

javac at mail dot com

Ryan Stewart

unread,
Jun 10, 2004, 7:40:53 PM6/10/04
to
"javac" <ja...@mail.com> wrote in message
news:64d923a9.0406...@posting.google.com...

> how does the directory structure effect netbeans? i alternate between
> the terminal (pico etc) and netbeans. basically, how do i get this to
> compile? it compiled fine before i added the first line: "package
> servlet.javac"
>
> FWIW, this is in reference to <http://www.myjavaserver.com/~javac/>
> and trying to get this servlet to to work there..
>
> --------netbeans-----------------------
> Exception in thread "main" java.lang.NoClassDefFoundError:
> WelcomeServlet3 (wrong name:
> servlet/javac/WelcomeServlet3)

Have you ever read the Java Tutorial?
http://java.sun.com/docs/books/tutorial/

It will solve all your command line woes. The packaging/naming/classpath
thing is a bit difficult to grasp at first. Say you're working in C:\java
(assuming a Windows OS of course). If you create some class in that
directory:
public class SomeClass {}

you can compile it like this: "javac SomeClass.java" and run it like this:
"java SomeClass". Simple. If you put it in a package like so:
package com.blah;
public class SomeClass {}

you can still compile it anywhere via "javac SomeClass.java". However, in
order to run it, first the class file must be at
C:\java\com\blah\SomeClass.class. Second, you must be executing the command
from C:\java. And finally, the command you must execute is "java
com.blah.SomeClass".

That should take care of your immediate need. However, also note that if you
have multiple classes that make use of each other, the placement of the
.java files is important as well. Assume you write two classes: One.java and
Two.java. One.java is in the com.blah package, and Two.java, which is used
by One.java, is in the com.otherblah package. If neither have been compiled
and you attempt to compile One.java, since the compiler needs Two.class, it
will try to compile Two.java. Where will it look for it? In
C:\java\com\otherblah.


Ryan Stewart

unread,
Jun 10, 2004, 7:42:12 PM6/10/04
to
"javac" <ja...@mail.com> wrote in message
news:64d923a9.0406...@posting.google.com...
> how does the directory structure effect netbeans? i alternate between
> the terminal (pico etc) and netbeans. basically, how do i get this to
> compile? it compiled fine before i added the first line: "package
> servlet.javac"

Oh sorry, that wasn't a command line question. Your last one was :) But the
same thing applies when you try to compile with NetBeans as with the command
line.


javac

unread,
Jun 11, 2004, 2:49:21 AM6/11/04
to
"Ryan Stewart" <zzanN...@gSPAMo.com> wrote in message news:<DrydnfDTP-j...@texas.net>...
[..]

thanks, ryan


-javac

0 new messages