java - 在Mustang(Java 1.6 sdk)中创建和发布Web服务的问题

标签 java .net web-services java-6

我对 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 示例/Calculator.java

然后

java -cp 示例.计算器

然后我尝试访问 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.

我不知道这是预期的行为还是其他什么。

非常感谢

最佳答案

对于最新的 Java 6,您不需要 apt 步骤。

此外,您的程序需要继续运行,否则它将在发布后立即关闭。

关于java - 在Mustang(Java 1.6 sdk)中创建和发布Web服务的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7170541/

相关文章:

c# - 如何使用 WSDL

.net - ASMX 用户名和密码安全

java - 当我使用 JSch 运行命令时删除不需要的字符

java - 是否有与 FontUtilities.getCompositeFontUIResource(Font) 等效的非专有等效项?

java - 如何使用 Java 驱动程序访问嵌套在 MongoDB 数组中的对象

.net - 我们可以在 MySQL 中动态创建表吗?

.net - HttpBrowserCapability.Crawler 属性 .NET

java - 如何让 lombok 与 Visual Studio Code 一起工作?

.net - 改进翻译人员和开发人员的工作流程

c# - 非常简单的网络服务 : take inputs, 电子邮件结果