using JAVA and Netbeans in Fedora core6
Hi jay73
i have created Hello.java in the /home/user/Desktop i have reinstalled fedora core 6 and i have set all the prerequisites for the jdk and tomcat..i have installed netbeans [environment variables] for the first time when i have run javac,java they worked ....but now not working i am getting the following error [root@localhost Desktop]# vi Hello.java [root@localhost Desktop]# javac Hello.java [root@localhost Desktop]# java Hello Exception in thread "main" java.lang.NoClassDefFoundError: Hello the content in the Hello.java file is as follows [root@localhost Desktop]$ cat Hello.java public class Hello{ public static void main (String [] args){ System.out.println("Hello"); } } edited lines in /etc/profile are as follows export JAVA_HOME=/opt/jdk1.6.0 export CATALINA_HOME=/opt/netbeans-5.5/enterprise3/apache-tomcat-5.5.17 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=/opt/netbeans-5.5/enterprise3/apache-tomcat-5.5.17/common/lib/servlet-api.jar content of $HOME/.bashprofile GNU nano 1.3.12 File: /root/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/opt/jdk1.6.0/bin export PATH unset USERNAME PLEASE HELP ME TO START WORKING WITH JAVA IN LINUX ABOUT THE SERVLET i have added CLASSPATH variable with the value /path_to_tomcat/common/bin/servlet.api.jar in the /etc/profile then i have compiled and class file is created in the pwd How to run this servlet form the browser i have saved the TestingServlet.java in /path_to_tomcat/webapps/my_apps/WEB-INF/ and a class file is created in this directory How to call this servlet form the browser I think you will be frustating to answer the strange problems of newbies like me....what do u feel....??? I am very thankful to you for having taken time to answer my questions .. No query of mine in this forum had these many replies that too from a single user..... |
|
Hi
Two remarks to begin with: 1) You shouldn't save your .java and .class files to your desktop, you'll make a complete mess. Place them in /home/username instead. 2) You don't need to be root to write and compile your java file in your home directory (that's the whole point of working in your home directory: it's the one place where a regular user can do pretty much as (s)he likes). If you work as root, you could (and probably will some day) make a mistake that destroys your system. Only become root when you need to move your files to a different directory. To make it work as a regular user, you need to edit the bash_profile in your own home directory as I described before (not in the root directory). Now, your problem. I don't really see why java Hello should fail this time if you did exactly what you did the first time. Let's go over the commands you used: vi Hello.java Vi was good for an example, but it may be easier to use another text editor, e.g. "gedit" or "leafpad". You could launch these directly by clicking their menu item instead of launching them from the command line. javac Hello.java If you don't receive any errors, then you're doing fine. java Hello NoClassDefFoundError basically means that java doesn't find the Hello.class file. That beats me. If you were able to compile in that directory, I don't see why you shouldn't be able to run the class file from there as well. Are you absolutely sure you didn't make any error (java is very sensitive to even the tiniest error: forgetting a space or writing a capital instead of a regular letter can be enough to get an exception or an error!). As for uploading to tomcat, I wouldn't do it the way you did it. I've always placed my stuff in a war file before uploading and I wouldn't be surprised if that's the only way to make it work. Anyway, use netbeans, that'll take care of everything (editing, paths, compilation, uploading,...) Here's just one example. As I said, I can't possibly even begin to show you how it works because there's so much to it. and the same goes, in fact, for Java, JSP and Servlets: it took me 3000 pages to become proficient so it's an illusion that I could teach you even the basic skills in a couple of posts. I suggest you look on the internet for some good tutorials. Start by learning some java, then do jSP and servlets (I think doing servlets without knowing java is pretty impossible because you need java to write them). Anyway, the netbeans example: 1) launch netbeans from the menu or from the desktop item 2) First check whether it is pointing towards your jdk (you need to do that only the first time): go to /Tools/Java Platform; it should be pointing to /opt/jdk1.6.0 if that's where your jdk is 3) Next you define your server: go to Tools/Server Manager: replace the default username and password with your own (this too needs be done only once) 4) Click File/new Project 5) Select Web and Web Application; click next 6) Define the project name (for example, myfirstservlet) and specify the Project Location (/home/username); leave the rest as it is 7) Click Next 8) Click Finish 9) Right-click on the project name in the left pane so a dialog pops up; select new; select servlet 10) Assign a Class name: for example, TestingServlet (I think that's what yours was called, right?) and define a Package: for example, com.me4linux.servlets 11) Click next and change the first letter of "URL pattern" with a regular letter (not a capital letter); do not delete the / or the rest of the word! Click Finish. 12) Now write your servlet: delete all the stuff from "response.setContentType" to "out.close()" and replace it with your own stuff. 13) In the left pane, under project name, unfold the directory tree and unfold Packages; select your servlet, do a right-click and click on Compile. If you get errors, there are mistakes in your servlet, you'll have to edit it first and then try compiling again until you get it right. 14) Next right-click on the project name in the left pane and select Deploy Project (netbeans will now upload your project/servlet to its tomcat server). 15) To see the page, you launch a browser and define the location of your servlet: http://localhost:XXXX/name of the project/url pattern of the servlet where XXXX is the port assigned to your Tomcat (look under Tools/Server Manager for the number: it's 4 digits) Where name of the project is the name you defined while making the project Where url pattern is the pattern defined while making the servlet if your port is, say, 8080 and you adopted all the values I suggested, you should use: http://localhost:8080/myfirstservlet/testingServlet Note: don't click on the urls above; they're just examples but this forum seems to turn them into real links no matter what I do. Note: using localhost on Fedora is a bit inconvenient at this time; you can use 127.0.0.1 instead of localhost. |
Try the commands
which java and which javac If its showing /usr/bin/java, it means its not using the correct java interpreter. For this you should use export PATH="/opt/jdk1.6.0/bin:$PATH" somewhere in your shell, bashrc, etc. |
To _UnPrEdictAbLe_
Errr............... Code:
$ ls -al /usr/bin/javac java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing) |
Hi everyone [especially jay73]
I have reinstalled fedora core 6 i386 yesterday and i have got the binary installtion file for netbeans "jdk-6-nb-5_5-linux.bin" Please explain me the steps in detail.. Being a newbie to linux I am fed up with reinstalling Fedora many times and messing up with may things Please help me to start java in fedora waiting for a nice reply bye |
You don't know how to install it, that's it?
Move the bin file to /opt cd to /opt As root, make the file executable: chmod a+x ./jdk* Then you install it: ./jdk*bin |
Hi,
In order to install the bin file, login as root. chmod 755 jdk-6-nb-5_5-linux.bin ./jdk-6-nb-5_5-linux.bin This will throw up a graphical interface. Install the jdk in /opt folder. It will also ask you to install netbeans in the /opt/netbeans-5.5 folder. After the installation finishes, you need to add the javac and java in the path. For that, you need to add these lines to /etc/bashrc export PATH="/opt/jdk1.6.0/bin:$PATH" (/opt/jdk1.6.0/bin should be replaced with whatever directory it is actually creating in /opt) The netbeans executable will be in /opt/netbeans-5.5/bin. Link it to /usr/bin cd /usr/bin ln -sf /opt/netbeans-5.5/bin/netbeans Then you can just type 'netbeans' on konsole or in run and get netbeans up and running. You should also check the jdk netbeans is using in its settings. It should use the /opt/jdk1.6.0 and so on. Also look for output of which java which javac They should point to executables in /opt and not /usr/bin Regards, unpredictable |
All times are GMT -5. The time now is 02:56 AM. |