从 Java 控制台应用程序和 ASP.NET 应用程序调用 Java

发布于 2024-09-07 18:06:45 字数 390 浏览 0 评论 0原文

最近我被要求为我的公司编写一个java应用程序。我是一名经验丰富的 .Net 开发人员,所以这对我来说是全新的领域。

我的任务是生成一个发票应用程序,该应用程序具有多个高级任务,例如:

  • 构建单个发票
  • 构建所有发票

我的公司希望能够从 java 控制台应用程序调用这些任务 - 传递相关命令和参数来调用任务。他们还希望能够从 ASP.NET 应用程序调用相同的代码。

因此我的第一个想法是使用 Java 中的 Web 服务。

我的问题是:我可以从 Java 控制台应用程序和 ASP.NET 应用程序中使用 Java 中的 Web 服务吗?或者也许有更好的选择。

任何让我朝正确方向研究的指示将不胜感激。

谢谢。

Recently I got asked to write a java application for my company. I'm a seasoned .Net developer so this is all new ground to me.

My task is to produce an invoicing application that has several high level tasks such as:

  • Build single invoice
  • Build all invoices

My company want to be able to call these tasks from a java console application - passing in relevant commands and parameters to invoke the tasks. They also want to be able to invoke the same code from an ASP.NET application.

Therefore my first thought was to use Web Services in Java.

My question is: Can I use Web Services in Java from both a Java Console Application and from an ASP.NET application? Or perhaps are there better alternatives.

Any pointers to get me researching in the right direction would be appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩余の解释 2024-09-14 18:06:45

“我的公司希望能够从 java 控制台应用程序调用这些任务 - 传递相关命令和参数来调用任务。他们还希望能够从 ASP.NET 调用相同的代码申请。”

我不确定您到底在问什么,但我认为简单的答案是确保您的应用程序具有入口点方法,以便它可以作为命令行应用程序运行。您需要一个具有如下所示方法的类:

package foo.bar;

public class Bazz {

    ...

    public static void main(String[] arguments) {
        // parse the arguments and run the application
        ...
    }
}

main 方法的签名至关重要:

  • 它必须是 public static
  • 它必须具有名称 main
  • 它必须附加一个 String[] 参数,并且
  • 必须具有 void 返回类型。

然后可以从命令行运行该命令,如下所示:

java -cp <YOUR_CLASS_PATH> foo.bar.Baz arg1 arg2 ...

这也可以通过另一个用 Java 编写的应用程序来完成,并且(我想)也可以通过 ASP.NET 来完成。

"My company want to be able to call these tasks from a java console application - passing in relevant commands and parameters to call the tasks. They also want to be able to call the same code from an ASP.NET application."

I'm not sure exactly what you are asking, but I think the simple answer is to ensure that your application has an entry point method so that it can be run as a command line applications. You need a class with a method that looks like this:

package foo.bar;

public class Bazz {

    ...

    public static void main(String[] arguments) {
        // parse the arguments and run the application
        ...
    }
}

The signature of the main method is critical:

  • it must be public static,
  • it must have the name main,
  • it must tack a single String[] argument and,
  • it must have a void return type.

This command can then be run from the command line as follows:

java -cp <YOUR_CLASS_PATH> foo.bar.Baz arg1 arg2 ...

This can also be done by another application written in Java, and (I imagine) from ASP.NET as well.

聽兲甴掵 2024-09-14 18:06:45

简单的答案是——是的。 Java 具有用于定义和部署 Web 服务的库,并且 Java 和 .NET 都有用于生成 Web 服务客户端的实用程序。但这并不是说这会很容易!

如果我是您,我会研究使用 JAX-RS 实现创建 REST 服务(我最喜欢的是 RestEASY)。这将允许您创建一个没有 SOAP 的“Web 服务”,即 http://server/invoices/1 可能会返回

<invoice>
 <items>
  <item>apple</item>
  <item>banana</item>
 <items>
 <customer>robert</customer>
 <amount>5.00</amount>
</invoice>

,然后它应该很容易用任何语言解释。不管怎样,这都将是一个陡峭的学习曲线。 Java 和 .NET 之间的主要区别在于,虽然许多功能内置于 .NET 中,但在 Java 中,它分布在整个生态系统中,这很好,因为它提供了多样性,但定位功能可能需要更长的时间。

The simple answer is - yes. Java has libraries for defining Web Services and deploying them, and both Java and .NET have utilities for generating Web Service clients. That's not to say it will be easy though!

If I was you, I would instead investigate creating a REST service using a JAX-RS implementation (my favourite is RestEASY). This will allow you to create a 'web service' without SOAP, i.e. http://server/invoices/1 might return

<invoice>
 <items>
  <item>apple</item>
  <item>banana</item>
 <items>
 <customer>robert</customer>
 <amount>5.00</amount>
</invoice>

Which it then should be easy to interpret in any language. Either way it will be a steep learning curve though. The main difference between Java and .NET is that while a lot of functionality is built in to .NET, in Java it's spread across the ecosystem, which is good because it provides variety, however it can take a bit longer to locate functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文