在 ant 编译中包含 JAR 文件 [英] Include JAR file in ant compilation

查看:30
本文介绍了在 ant 编译中包含 JAR 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些 .java 文件编译成 JAR.我想在另一个应用程序中使用这个 JAR 文件.

I want to compile some .java files into a JAR. I would like to use this JAR file in another application.

这是在我的第二个应用程序中使用我的第一个应用程序中的函数的好方法吗?我的目标是不重复代码.

Is this a good way to use functions from my first application in my second application? My goal is to not duplicate code.

如何编辑第二个应用程序的 build.xml 文件以包含我创建的 JAR 文件?当我编译我的项目时,JAR 文件中的函数没有解析:

How can I edit the build.xml file for the second application to include the JAR file I created? When I compile my project, functions from JAR files are not resolved :

[javac] C:\HelloWorld\src\com\example\helloworld\HelloWorld.java:7: 
        package TOOLS does not exist  
[javac] import TOOLS.Logs;

<小时>


当我在 build.xml 中添加 javac 任务时,编译失败,因为找不到其他包:



When I add the javac task in my build.xml, compilation fails because other packages are not found:

[javac] Compiling 1 source file
[javac] C:\HelloWorld\src\com\example\hellowolrd\HelloWorld.java:3: 
        package android.app does not exist
[javac] import android.app.Activity;
[javac]                   ^

为什么在我包含 JAR 文件后找不到我的原始包?

Why are my original packages not found after I include the JAR file?

推荐答案

是的.通常将功能细分为库以便重用、易于开发等是一种很好的做法.如果单独构建它们会加快开发速度,并且您可以轻松地将功能分发到连续的项目.

Yes. It's good practice generally to subdivide functionality into libraries for reuse, ease-of-development etc. It'll speed development if they're separately built, and you can easily distribute functionality to successive projects.

你可以这样引用你的罐子:

You can reference your jar thus:

  <javac srcdir="${src}"
         destdir="${build}"
         classpath="xyz.jar"
         debug="on"
  />

请参阅javac 文档以获取更多信息.

See the javac documentation for more information.

这篇关于在 ant 编译中包含 JAR 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆