java Rxtx library issue

i'm trying to establish a serial communcation bewteen my pc and arduino by java and i have used Rxtx library and followed the tutorial in this website: Arduino Playground - Java
i just don't know what to do next because when i run the the java application first it runs properly but i get an error "serial port already in use" when i try to open the arduino serial monitor.
and vise versa if i open the arduino serial monitor first i get this error "gnu.io.PortInUseException: Unknown Application" in the java console.
i'm newbie in using the Rxtx library so can you tell me what am i missing.
i need to send messages from the java console to arduino and see the output in the serial monitor.

i need to send messages from the java console to arduino and see the output in the serial monitor.

I'm pretty sure you won't be able to do this. You can either use the serial monitor to send and receive messages or use java to send and receive messages not both. Usually connecting to a port will block the port from further connections.

allright, never mind seeing what's happening on the serial monitor in arduino.
i have wrote this code:

int led = 13;
void setup() {                
Serial.begin(9600);
pinMode(led, OUTPUT);     
}

void loop() {
  char c=Serial.read();
  if(c=='1')
 {
  digitalWrite(led, HIGH);
 }
else if(c=='2')
  {
  digitalWrite(led, LOW); 
}
}

but when i input 1 or 2 in the java console nothing happens, is there something wrong with my syntax of how to recieve data?

but when i input 1 or 2 in the java console nothing happens, is there something wrong with my syntax of how to recieve data?

No, but there could be something wrong in how you send the data.

i got the java code from the arduino website: "Arduino Playground - Java" just as it is and just added these lines:

char ch = '1';
output.write(ch);

insdie the try statement so it looks like this now:

try {
			// open serial port, and use class name for the appName.
			serialPort = (SerialPort) portId.open(this.getClass().getName(),
					TIME_OUT);

			// set port parameters
			serialPort.setSerialPortParams(DATA_RATE,
					SerialPort.DATABITS_8,
					SerialPort.STOPBITS_1,
					SerialPort.PARITY_NONE);

			input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
			 output = serialPort.getOutputStream();
			 char ch = '1';
			 output.write(ch);
			// add event listeners
			serialPort.addEventListener(this);
			serialPort.notifyOnDataAvailable(true);
			
		} catch (Exception e) {
			System.err.println(e.toString());
		}

so that it should send character '1' serially, which i programmed if received to set pin 13 to high , but also nothing happens!

When you open the serial port, the Arduino resets, unless you've modified it not to do that. You are sending data before the Arduino has a chance to boot up. Of course it then ignores that data.

so where should i place this line : "output.write(ch);" to send a character properly.
i have made output a global variable and placed this line somewhere here at the end:

public static void main(String[] args) throws Exception {
		SerialTest main = new SerialTest();
		main.initialize();
		Thread t=new Thread() {
			public void run() {
				//the following line will keep this app alive for 1000 seconds,
				//waiting for events to occur and responding to them (printing incoming messages to console).
				try {Thread.sleep(1000000);} catch (InterruptedException ie) {}
			
			}
		};
		t.start();
		char ch = '1';
		 output.write(ch);
		System.out.println("Started");

still no response

What is the relationship between the SerialTest instance main (lousy name!) and the Thread t?

Perhaps you could get some help at http://snippets-r-us.com.

the example here works perfectly fine: http://rxtx.qbang.org/wiki/index.php/Two_way_communcation_with_the_serial_port ,
thank you for your help