run javacode from matlab

1 vue (au cours des 30 derniers jours)
sshree
sshree le 21 Fév 2012
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

Réponses (1)

Stephen
Stephen le 22 Fév 2012
It is easier then that. Directly inside MATLAB:
client = org.apache.commons.net.time.TimeTCPClient;
client.connect(hist1-ny.ustiming.org)
t = client.getDate()

Catégories

En savoir plus sur Java Package Integration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by