run javacode from matlab

조회 수: 2 (최근 30일)
sshree
sshree 2012년 2월 21일
PLEASE help me sir .I am _novice(_just more than) level user . I want to run the below java code in matlab workspace .
It ran successfully in JAVA environment .
I have added the path of classfile generated after compiling this programme and apache jar file in static path by editing classpath.txt.
I went through the MATLAB External API reference guide but I am not able to get it.
I used javaclasspath command to see my added path and it showed that it is there.
version of softwares that i use
MATLAB Version 7.7.0.471 (R2008b)
Operating System: Microsoft Windows Vista Version 6.1 (Build 7600)
Java VM Version: Java 1.6.0_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode**
**JAVA CODE**
import java.io.IOException;
import org.apache.commons.net.TimeTCPClient;// third party class
public final class TimeClient
{
public static final void timeTCP(String host) throws IOException
{
TimeTCPClient client = new TimeTCPClient();
try {
// We want to timeout if a response takes longer than 4 seconds
client.setDefaultTimeout(4000);
client.connect(host);
System.out.println(client.getDate());
}
finally {
client.disconnect();
}
}
public static final void main(String[] args)
{
{
try
{
timeTCP(args[0]);
}
catch (IOException e)
{e.printStackTrace();
System.exit(1);
}
}
}
} please help me.
Thanks Saurabh

답변 (1개)

Stephen
Stephen 2012년 2월 22일
It is easier then that. Directly inside MATLAB:
client = org.apache.commons.net.time.TimeTCPClient;
client.connect(hist1-ny.ustiming.org)
t = client.getDate()

카테고리

Help CenterFile Exchange에서 Java Package Integration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by