“提供”构建中未使用conf ivy依赖项
我正在使用 Netbeans 构建 Web 应用程序(使用 Tomcat 和 Java)。
我使用 Ant 进行构建,使用 Ivy 进行依赖管理。
以前,我没有在依赖项上设置 conf
属性,只是将它们全部包含在我的 WEB-INF/lib
文件夹中。 现在,我希望某些 JAR
仅用于编译,而不与我的应用程序捆绑在一起(即:“提供”范围): servlet-api.jar
, <代码>el-api.jar、jsp-api.jar
。
因此,我将 conf
属性添加到了 ivy.xml
中的依赖项元素,并添加了 configurations
,如下所示
<configurations>
<conf name="compile" description="Required to compile application"
visibility="public"/>
<conf name="runtime" description="Additional run-time dependencies"
visibility="public" extends="compile"/>
<conf name="test" description="Required for test only"
visibility="public" extends="runtime"/>
<conf name="provided" description="Needed for compile, but will be present on the target platform."
visibility="public"/>
</configurations>.
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency org="javax.servlet" name="javax.servlet-api" rev="3.1.0"
conf="provided->master"/>
<!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
<dependency org="javax.el" name="javax.el-api" rev="3.0.1-b06"
conf="provided->master"/>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency org="javax.servlet.jsp" name="javax.servlet.jsp-api" rev="2.3.3"
conf="provided->master"/>
</dependencies>
:省略上面代码中的所有“常规”依赖项,其中我没有指定 conf
因为它们将包含在编译和运行时。
我调用一个任务来解析和检索运行时 JAR,并将它们放置在我的应用程序的 WEB-INF/lib 中,如下所示:
<target name="-ivy-retrieve">
<ivy:resolve/>
<ivy:cachepath pathid="compile.path" conf="compile,provided"/>
<ivy:retrieve sync="true" conf="runtime"/> <!-- Load dependencies to the project -->
<pathconvert property="ivy.classpath.computed" dirsep="/" pathsep=":">
<path>
<fileset dir="lib" includes="*.jar"/>
</path>
<map from="${basedir}${file.separator}" to=""/>
</pathconvert>
<propertyfile file="nbproject/project.properties">
<entry operation="=" key="ivy.classpath" value="${ivy.classpath.computed}"/>
</propertyfile>
</target>
<target name="-pre-compile" depends="-ivy-retrieve"/>
<target name="-pre-compile-single" depends="-ivy-retrieve"/>
<target name="-post-clean">
<delete dir="lib"/>
</target>
这会将必要的 JAR 拉入我的 WEB-INF/lib 中。
我可以部署。但是,我不确定如何将 compile.path
cachepath
集成到我的构建中,以便这些 JAR
(即:serlvet -api.jar
、el-api.jar
、jsp-api.jar
)可供编译。 结果,我在部署后收到一大堆日志错误(我认为这表明这些 JAR
在编译期间不可用)。
我在 build-impl.xml
中找到了一个编译目标:
<target depends="init, deps-jar, -pre-pre-compile, -pre-compile, -copy-manifest, -copy-persistence-xml, -copy-webdir, library-inclusion-in-archive,library-inclusion-in-manifest" if="have.sources" name="-do-compile">
<webproject2:javac destdir="${build.classes.dir}" gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
但是,我不太确定如何设置该目标的类路径(我尝试添加一个 classpathref
属性webproject:javac
元素,但这会导致错误,因为该属性无法识别)。
我还尝试在单独的元素中定义类路径,如下所示:
<classpath refid="compile.path" />
立即跟随 webproject2:javac
行,但这也会产生错误
问题:无法创建任务或键入类路径原因:名称是 未定义。
请解释如何调整我的构建,以便正确使用 provided
conf
依赖项。
I am using Netbeans to build a web application (with Tomcat & Java).
I use Ant for the build and Ivy for dependency management.
Previously, I did not set the conf
attribute on the dependencies and just included them all in my WEB-INF/lib
folder.
Now, I would like certain JARs
to only be used for compiling and not be bundled with my application (ie: 'provided' scope): servlet-api.jar
, el-api.jar
, jsp-api.jar
.
As a result, I added the conf
attribute to the dependency elements in my ivy.xml
as well as adding configurations
as follows:
<configurations>
<conf name="compile" description="Required to compile application"
visibility="public"/>
<conf name="runtime" description="Additional run-time dependencies"
visibility="public" extends="compile"/>
<conf name="test" description="Required for test only"
visibility="public" extends="runtime"/>
<conf name="provided" description="Needed for compile, but will be present on the target platform."
visibility="public"/>
</configurations>.
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency org="javax.servlet" name="javax.servlet-api" rev="3.1.0"
conf="provided->master"/>
<!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
<dependency org="javax.el" name="javax.el-api" rev="3.0.1-b06"
conf="provided->master"/>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency org="javax.servlet.jsp" name="javax.servlet.jsp-api" rev="2.3.3"
conf="provided->master"/>
</dependencies>
I'm leaving out all the "regular" dependencies from the code above where I didn't specify a conf
as they are to be included for compiling and for runtime.
I call a task in order to resolve and retrieve the runtime JARs and place them in my application's WEB-INF/lib like so:
<target name="-ivy-retrieve">
<ivy:resolve/>
<ivy:cachepath pathid="compile.path" conf="compile,provided"/>
<ivy:retrieve sync="true" conf="runtime"/> <!-- Load dependencies to the project -->
<pathconvert property="ivy.classpath.computed" dirsep="/" pathsep=":">
<path>
<fileset dir="lib" includes="*.jar"/>
</path>
<map from="${basedir}${file.separator}" to=""/>
</pathconvert>
<propertyfile file="nbproject/project.properties">
<entry operation="=" key="ivy.classpath" value="${ivy.classpath.computed}"/>
</propertyfile>
</target>
<target name="-pre-compile" depends="-ivy-retrieve"/>
<target name="-pre-compile-single" depends="-ivy-retrieve"/>
<target name="-post-clean">
<delete dir="lib"/>
</target>
This pulls the necessary JARs into my WEB-INF/lib.
I am able to deploy. However, I'm not sure how to integrate the compile.path
cachepath
into my build so that these JARs
(ie: serlvet-api.jar
, el-api.jar
, jsp-api.jar
) are available for compiling.
As a result, I get a whole bunch of log Errors after deploying (which I think indicates that these JARs
were not available during compiling).
I found a compile target in build-impl.xml
:
<target depends="init, deps-jar, -pre-pre-compile, -pre-compile, -copy-manifest, -copy-persistence-xml, -copy-webdir, library-inclusion-in-archive,library-inclusion-in-manifest" if="have.sources" name="-do-compile">
<webproject2:javac destdir="${build.classes.dir}" gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
However, I'm not quite certain how to set the classpath for this target (I tried adding a classpathref
attribute to the webproject:javac
element, but this caused an error as this attribute is not recognized there).
I also tried defining the classpath in a separate element like so:
<classpath refid="compile.path" />
Immediately following the webproject2:javac
line but this also yields an error
Problem: failed to create task or type classpath Cause: The name is
undefined.
Please explain how to adjust my build so that the provided
conf
dependencies will be used correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论