run javacode from matlab

1 回表示 (過去 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 Center および File ExchangeJava Package Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by