compile java in gedit

Asked by whitepaper

I am a new user in ubuntu
I don't know how to compile ad run java file using gedit or any other editor in unbutu
please help.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gedit Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#1

Please tell do you want automate gedit (gedit is an editor) to compile java source...?

Thank you

Revision history for this message
Tiefflieger (tiefflieger) said :
#2

Lets suppose you created a Java-program in a file named "myfirstjavaprogram.java" in any editor you'd like. To run that program, you need to enter following commands at the console in the directory where this file resides:

javac myfirstjavaprogram.java
java myfirstjavaprogram

Revision history for this message
whitepaper (abdullahallmehedi) said :
#3

 marcobra said 51 minutes ago:

Please tell do you want automate gedit (gedit is an editor) to compile java source...?

Thank you

No I don't automate gedit to compile java and I want to knoe how can I do that.

Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#4

So Tiefflieger has already give you the right answer.
Do you have already installed a Java jdk for example the sun-java6-jdk ?

Thank you

Revision history for this message
peter (peter-neuweiler) said :
#5

I recommend to use Bluefish instead of gedit. You can find Bluefish in the Synaptic package manager.

Bluefish is an editor for experienced web designers and programmers. It supports many programming and markup languages, but focuses on editing dynamic and interactive websites.

Hope it helps.
Peter

Revision history for this message
whitepaper (abdullahallmehedi) said :
#6

When I write the command "javac Mehedi.java" as Tiefflieger suggested the following message has shown

>javac: file not found: Mehedi.java
>Usage: javac <options> <source files>
>use -help for a list of possible options

My file resides at desktop and I have installed sun-java6-jdk . I use the Terminal option to write command , but I don't know how to enter commands "at the console in the directory where the file resides".

Plz explain me.

Revision history for this message
Curtis Hovey (sinzui) said :
#7

Most developers us make and a Makefile to compile their projects, and gedit's external tools support make with the Build command (<Control>F8). So the easiest way to manage a Java project is to copy a generic Makefile to your project's directory.

Here is a page that document's a Java Makefile
     http://www.cs.swarthmore.edu/~newhall/unixhelp/javamakefiles.html

Revision history for this message
Tiefflieger (tiefflieger) said :
#8

You need to be in the directory where the file is. So in case the file is on your Desktop, you would open a new terminal and type in the following commands:

cd Desktop
javac Mehedi.java
java Mehedi

Revision history for this message
newbean (newbean) said :
#9

Here is how I created a javac tool for gedit:

1. Go to Tools --> External Tools

2. Click on New button.
    (The external Tools Manager dialog appears.
    Notice the Tools: list on the left side. You should see "New Tool" highligted.)

3. Click the highlighted "New Tool" in the tools list box.

4. Typein "javac" (or whatever you want to call it)

5. Fill out the description box.

6. If you want to use a shortcut key (eg. Control F6),
    in the shortcut key box type <CONTROL>F6

7. The commands box is used to define your macro.
    It's just a linux script.
    I'll be using bash script.

    Type the following in the command box:

#! /bin/bash

# Store the file name in a variable
FILE_NAME=$GEDIT_CURRENT_DOCUMENT_NAME
FILE_NAME_BASE=`echo "$FILE_NAME" | cut -d "." -f 1`;
FILE_NAME_DIR=$GEDIT_CURRENT_DOCUMENT_DIR

# Check if file extension is .java
if [ `echo $FILE_NAME | cut -d "." -f 2` = "java" ]; then
   /opt/Sun/jdk1.6.0_06/bin/javac $FILE_NAME
   echo -e " Created: $FILE_NAME_DIR/$FILE_NAME_BASE.class"
else
   echo -e "\n Filename must have a \".java\" extension."
  echo; echo
fi

8. In the Input dropdown, Select "Current Document"

9. In the Output dropdown, Select "Display in bottom pane"

10. In the Applicability dropdown, Select "All Documents"

11. Press the Close button

Finally:
Open up or save a current java file with a .java extension.
Go to Tools --> javac

Your new tool will compile your java file and display some basic info.

Hope you like it.

Newbean

Can you help with this problem?

Provide an answer of your own, or ask whitepaper for more information if necessary.

To post a message you must log in.