在Mustang(Java 1.6 sdk)中创建和发布Web服务的问题
我对 Java 很陌生,并且在 dotnet 方面有一些经验。目的是在 java (jdk 1.6) 中创建一个 Web 服务并通过 dotnet 使用它。请假设我是 Java 初学者。
我在使用 Java 创建 Web 服务时陷入困境(我是新手)..这是我的程序(示例取自 net)
package example;
import javax.jws.WebService;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class Calculator {
@WebMethod(action="addNumbers")
public int Add(int number1, int number2) {
return number1 + number2;
}
}
public static void main(String[] args)
{
Calculator server = new Calculator ();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/AddWebService", server);
}
所以在创建这个之后,我将其保存为 Calculator.java 在 C:\Program 中Files\Java\jdk1.6.0\bin
然后首先我编译为
apt -d example/Calculator.java
然后
java -cp example.Calculator
然后我尝试访问 wsdl 文件 http://localhost:8080/AddWebService?wsdl 但没有结果...您能帮我一下吗我做错了..
编辑
在我运行 apt 之后,
-d example/Calculator.java
我在控制台中得到了以下内容
warning: The apt tool and its associated API are planned to be
removed in the next major JDK release. These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model. Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.
Usage: apt <apt and javac options> <source files>
where apt options include:
-classpath <path> Specify where to find user class files and annotati
on processor factories
-cp <path> Specify where to find user class files and annotati
on processor factories
-d <path> Specify where to place processor and javac generate
d class files
-s <path> Specify where to place processor generated source f
iles
-source <release> Provide source compatibility with specified release
-version Version information
-help Print a synopsis of standard options; use javac -he
lp for more options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-A[key[=value]] Options to pass to annotation processors
-nocompile Do not compile source files to class files
-print Print out textual representation of specified types
-factorypath <path> Specify where to find annotation processor factorie
s
-factory <class> Name of AnnotationProcessorFactory to use; bypasses
default discovery process
See javac -help for information on javac options.
在我运行之后,
java -cp example.Calculator
我在控制台中收到了以下内容,
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://java.sun.com/javase/reference for more details.
我不知道这是预期的行为还是其他什么。
多谢
I am preety new to Java and have some experience in dotnet. The intension is to create a web service in java (jdk 1.6) and consume it thru dotnet. Please assume me as a beginner in Java.
I got stuck up in creating a web service using Java(I am new to it).. here is my program(sample taken from net)
package example;
import javax.jws.WebService;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class Calculator {
@WebMethod(action="addNumbers")
public int Add(int number1, int number2) {
return number1 + number2;
}
}
public static void main(String[] args)
{
Calculator server = new Calculator ();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/AddWebService", server);
}
So after creating this I saved it as Calculator.java in C:\Program Files\Java\jdk1.6.0\bin
Then first I compiled as
apt -d example/Calculator.java
and then
java -cp example.Calculator
And then I tried to access the wsdl file as http://localhost:8080/AddWebService?wsdl but with no result... Could you please help me as what wrong I am making..
EDIT
After I ran apt
-d example/Calculator.java
I got the below in the console
warning: The apt tool and its associated API are planned to be
removed in the next major JDK release. These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model. Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.
Usage: apt <apt and javac options> <source files>
where apt options include:
-classpath <path> Specify where to find user class files and annotati
on processor factories
-cp <path> Specify where to find user class files and annotati
on processor factories
-d <path> Specify where to place processor and javac generate
d class files
-s <path> Specify where to place processor generated source f
iles
-source <release> Provide source compatibility with specified release
-version Version information
-help Print a synopsis of standard options; use javac -he
lp for more options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-A[key[=value]] Options to pass to annotation processors
-nocompile Do not compile source files to class files
-print Print out textual representation of specified types
-factorypath <path> Specify where to find annotation processor factorie
s
-factory <class> Name of AnnotationProcessorFactory to use; bypasses
default discovery process
See javac -help for information on javac options.
And after I ran
java -cp example.Calculator
I recived the below in console
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://java.sun.com/javase/reference for more details.
I donot know is it the expected behaviour or something else.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要使用最新的 Java 6 的 apt 步骤。
此外,您的程序需要继续运行,否则它将在发布后立即关闭。
You do not need the apt step with the latest Java 6.
Also your program needs to keep running or it will just shut down immediately after publishing.
该错误是因为您的 java 命令参数错误。您要运行的 java 命令类似于,
请注意 -cp 之后的 ,。
这是一个很好的 Java 入门 页面
The error is because you have the wrong java command arguments. The java command you want to run will be something like,
Note the , after -cp.
This is a good getting started page for java