I'm trying to build a restful server using Apache Jersey. I'm developing in Eclipse Indigo and using Ivy for dependency management with this ivy.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!--=========================================================================-->
<!--
-->
<!--=========================================================================-->
<ivy-module version="2.2">
<info organisation="com.mypackage" module="mymodule"/>
<dependencies>
<dependency org="com.sun.jersey" name="jersey-servlet" rev="1.12"/>
</dependencies>
</ivy-module>
This resolves fine calling ivy from ant, but from IvyDE I get this error
Some projects fail to be resolved
Impossible to resolve dependencies of com.mypackage#mymodule;working#Samsung-Windows
unresolved dependency: org.jboss.weld#weld-spi;1.1.4.Final: not found
unresolved dependency: javax.annotation#jsr250-api;${jsr250.api.version}: not found
unresolved dependency: org.jboss.weld#weld-api;1.1.4.Final: not found
unresolved dependency: javax.inject#javax.inject;${atinject.api.version}: not found
unresolved dependency: org.jboss.spec.javax.interceptor#jboss-interceptors-api_1.1_spec;${interceptor.api.version}: not found
To me the ${atinject.api.version} looks like it is somehow not resolving variables correctly somewhere.
My understanding of Ivy is very superficial, so I don't have any good ideas.
Both IvyDE and ant are using the same ivysettings.xml file (at least, I believe they are).
<?xml version="1.0" encoding="UTF-8"?>
<!--=========================================================================-->
<!--=========================================================================-->
<ivysettings>
<settings defaultResolver="ibiblio"/>
<resolvers>
<ibiblio name="ibiblio" m2compatible="true"/>
<ibiblio name="maven2" m2compatible="true"/>
<ibiblio name="java-net-maven1" root="http://download.java.net/maven/1" pattern="${java.net.maven.pattern}" m2compatible="false"/>
<ibiblio name="java-net-maven2" root="http://download.java.net/maven/2/" m2compatible="true"/>
</resolvers>
</ivysettings>
Any direction would be great.
Thanks a lot in advance.
Edit: Adding portion of Build.xml
I'm using apache-ivy-2.2.0 although the output claims:
[ivy:configure] :: Apache Ivy 2.3.0-rc1 - 20120416000235 :: http://ant.apache.org/ivy/ ::
This is the build.xml:
<?xml version="1.0"?>
<project name="IvyTest" default="ivy.retrieve" xmlns:ivy="antlib:org.apache.ivy.ant">
<description>
IvyTest
</description>
<!--=====================================================================-->
<!-- Properties -->
<!--=====================================================================-->
<!-- General properties. -->
<property name="bin" location="bin" />
<property name="lib" location="lib" />
<property name="lib.ivy" location="${lib}/ivy-managed" />
<property name="ivy.version" value="2.2.0" />
<property name="ivy.home" location="${bin}/apache-ivy-${ivy.version}" />
<available property="ivy.installed" file="${ivy.home}/ivy-${ivy.version}.jar" />
<property name="ant.build.javac.source" value="1.7" />
<property name="ant.build.javac.target" value="1.7" />
<!--=====================================================================-->
<!-- Targets: Ivy -->
<!--=====================================================================-->
<!--============================ ivy.download ===========================-->
<target name="ivy.download" unless="ivy.installed">
<mkdir dir="${ivy.home}"/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" dest="${ivy.home}/ivy-${ivy.version}.jar" usetimestamp="true"/>
</target>
<!--============================ ivy.init ===============================-->
<target name="ivy.init" depends="ivy.download">
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${ivy.home}/ivy-${ivy.version}.jar"/>
</target>
<!--============================ ivy.resolve ============================-->
<target name="ivy.resolve" description="Resolve dependencies with Ivy" depends="ivy.configure">
<ivy:resolve />
</target>
<!--============================ ivy.retrieve ===========================-->
<target name="ivy.retrieve" description="Retrieve dependencies with Ivy" depends="ivy.configure">
<ivy:retrieve log="verbose" pattern="${lib.ivy}/[artifact]-[revision].[ext]" type="jar,bundle" sync="true"/>
</target>
<!--============================ ivy.configure ==========================-->
<target name="ivy.configure" description="Configure Ivy settings file" depends="ivy.init">
<ivy:configure file="ivysettings.xml"/>
</target>
<!--============================ ivy.clean ==============================-->
<target name="ivy.clean" description="Cleans the Ivy cache" depends="ivy.init">
<ivy:cleancache />
</target>
</project>
By default ivy will download dependencies from Maven Central, so unless you're using your own Maven repository manager you won't need an ivy settings file.
Having said that it's good practice to declare one and the following works fine for me:
<ivysettings>
<settings defaultResolver="central"/>
<resolvers>
<ibiblio name="central" m2compatible="true"/>
</resolvers>
</ivysettings>
Notice it's a lot simpler than your example. The old java.net repositories are not really used anymore, most (if not all) of their content has been migrated to Maven Central.
As an update to your original question:
I also had the situation that I could resolve on the console using ant resolve but IvyDe (under Eclipse 4.2) was giving me the error "Impossible to resolve dependencies [...]"
Lead through this post I managed to edit IvyDE's settings (Workspace Preferences -> Ivy -> Settings) and add an ivysettings.properties file with this content:
ivy.home=${user.home}/.ant
ivy.jar.dir=${ivy.home}/lib
ivy.jar.file=${ivy.jar.dir}/ivy.jar
From now on everything worked fine.
Related
I have a simple web application developed in the Eclipse Luna. The directory structure of the application is like:
Project name is SchoolSchedule.
Under the project name, there are Java Resources, build, WebContent folders, and the build.xml file.
Under Java Resources, it is the "src" folder and my Java code package name is under the "src" folder.
Under the WebContent, there are META-INF, WEB-INF and my jsp files
Under the WEB-INF, there are web.xml file and the "lib" directory.
The build.xml is at the project root. This web application runs successfully and produces expected results.
I created an Ant script to compile, build a WAR file, and deploy the WAR. But, even the basic task does not work. I right click on the build.xml --> run as ... --> Ant build. In the console, I can see all the echo messages and no error. However, I do not see any new directories created (I "refresh" the project.). No "class" files compiled from the Java code and not to mention build and deploy those tasks.
There is something I did not get it right. Please help. Here is my Ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntWarWebApp" basedir="." >
<echo>Define properties</echo>
<property name="name" value="SchoolSchedule"/>
<property name="src" location="src"/>
<property name="web" location="WebContent"/>
<property name="build" location="build"/>
<property name="classDir" location="${build}/src"/>
<property name="distDir" location="${build}/dist"/>
<property name="warDir" location="${build}/war"/>
<property name="tomcat.webapps" value="C:\apache-tomcat-7.0.70\webapps" />
<echo>time stamp</echo>
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<echo>clean up previous build directories</echo>
<target name="clean" description="Delete old build directories">
<delete dir="${distDir}"/>
<delete dir="${warDir}"/>
<delete dir="${classDir}"/>
</target>
<echo>create directories</echo>
<target name="init" depends="clean">
<mkdir dir="${build}"/>
<mkdir dir="${classDir}"/>
<mkdir dir="${warDir}"/>
<mkdir dir="${distDir}"/>
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
</target>
<echo>start compiling</echo>
<target name="compile" depends="clean, init" description="Compile main
source tree java files">
<javac srcdir="${src}" destdir="${classDir}" />
<classpath>
<fileset dir="${basedir}/WebContent/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</target>
<echo>start building WAR file</echo>
<target name="buildwar" depends="clean, init, compile">
<war basedir="${wardir}" destfile="${distDir}/${name}.war"
webxml="${wardir}/WEB-INF/web.xml">
<webinf dir="${wardir}/WEB-INF/">
<include name="**/*.jar" />
</webinf>
<manifest>
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
<echo>end building WAR file</echo>
<target name="deploy" depends="init, compile, buildwar" description="Deploy application">
<delete dir="${tomcat.webapps}/*.war" />
<echo>copy WAR file to Tomcat deploy directory</echo>
<copy file="${distdir}/*.war" todir="${tomcat.webapps}" />
</target>
</project>
Aren't you supposed to have some kind of top-level element
<project>
....
</project>
around all this?
I'm using some apache HttpClient jars, so I put them in my project's lib directory, when Netbeans compiles the project, it copies the lib and generated a project jar into dist directory, but when I run my project with webstart, I need to copy the project jar and lib into tomcat's ROOT dir, I wonder if Netbeans can generate a project jar that includes all the jars in the lib dir, so I don't have to copy the project jar and the lib dir into tomcat's ROOT dir. Can Netbeans do that ?
That's really easy to package every dependent library (*.jar) into one single myProject.jar.
Just follow these steps and you will finally pack every dependent library into single jar. If you are using NetBeans then you can follow exactly or else you need to find your build.xml file in project files.
Follow these steps to edit build.xml
1) Click on Files tab on the left side of the project panel in NetBeans.
2) Double click on the build.xml file and add these lines in it just before </project> line
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="myProject"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
3) Change value in second line of the code as per your project name which is
<property name="store.jar.name" value="myProject"/> //<---Just value not name
4) Save it and right click on build.xml and choose Run Target and then Other Targets and finally click on Package-for-store
5) And here you done. Now you can go and check just like dist folder there will be a store folder which will be containing your final complete jar including all of your dependent libraries. Now whenever you want to change / add more libraries or so, just follow step 4.
Picture for step 4
OK, found the answer at the following site : http://arunasujith.blogspot.com/2011/08/how-to-build-fat-jar-using-netbeans.html
Robert Eckstein describes a solution for this problem. You just need to paste the following code to build.xml. The libraries are all found automatically.
Here we go:
<target name="-post-jar">
<!-- Change the value to the name of the final jar without .jar -->
<property name="store.jar.name" value="MyJarName"/>
<!-- don't edit below this line -->
<property name="store.dir" value="dist"/>
<property name="temp.dir" value="temp"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${temp.dir}"/>
<mkdir dir="${temp.dir}"/>
<jar destfile="${temp.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<delete dir="${store.dir}"/>
<zip destfile="${store.jar}">
<zipfileset src="${temp.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete dir="${temp.dir}"/>
</target>
Go to your build.xml, and add the code right before the closing project tag at the end.
Now change the value of the first propertiy field as commented
Click Clean & Build, and your jar will be in the dist folder
Reference link:
https://stackoverflow.com/a/30172829/2761273
check MainClass main file is updated as main file in Properties>run
Update Build.xml with following code before project tag closes
<!-- Change the value to the name of the final jar without .jar -->
<property name="store.jar.name" value="MyJarName"/>
<!-- don't edit below this line -->
<property name="store.dir" value="dist"/>
<property name="temp.dir" value="temp"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${temp.dir}"/>
<mkdir dir="${temp.dir}"/>
<jar destfile="${temp.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<delete dir="${store.dir}"/>
<zip destfile="${store.jar}">
<zipfileset src="${temp.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete dir="${temp.dir}"/>
Properties>packaging> tick all
clean and build
Upload to server.
Okay, so this is my solution. I too had the problem with my program compiling and running on Netbeans but it failing when I tried java -jar MyJarFile.jar. Now, I don't fully understand Maven and I think this why was having trouble getting Netbeans 8.0.2 to include my jar file in a library to put them into a jar file. I was thinking about how I used to use jar files with no Maven in Eclipse.
It's Maven that compiles all the dependencies and plugins, not Netbeans. (If you can get Netbeans to do this please tell us how.)
[Solved - for Linux] by opening a terminal.
Then
cd /MyRootDirectoryForMyProject
Next
mvn org.apache.maven.plugins:maven-compiler-plugin:compile
Next
mvn install
This will create jar file in the target directory.
MyJarFile-1.0-jar-with-dependencies.jar
Now
cd target
(You may need to run: chmod +x MyJarFile-1.0-jar-with-dependencies.jar)
And finally
java -jar MyJarFile-1.0-jar-with-dependencies.jar
Please see
https://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
I'm using Scala IDE 2.0.1 and SBT 0.11.2 to start with Akka 2.0.1. My build.sbt looks like this:
name := "akka"
version := "0.1"
scalaVersion := "2.9.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.1"
As you can see, there's nothing spectacular.
Now how can I tell Eclipse to use the artifact with the sources classifier for the akka-actor library?
In SBT, I can use update-classifiers to download sources and Javadocs to the Ivy repository, but even if I do this before running the eclipse command from the sbteclipse plugin then Eclipse still does not know the sources. Of course, I could do this manually, but this doesn't scale well for more libraries.
I have also tried to use the IvyDE plugin with the deliver-local command. While this integrates the dependency management, it doesn't seem to help with the sources.
Any clues?
Edit: This is the ivy.xml generated from deliver-local:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="default" module="akka_2.9.2" revision="0.1" status="release" publication="20120506225613">
<description>
akka
</description>
</info>
<configurations>
<conf name="compile" visibility="public" description=""/>
<conf name="runtime" visibility="public" description="" extends="compile"/>
<conf name="test" visibility="public" description="" extends="runtime"/>
<conf name="provided" visibility="public" description=""/>
<conf name="optional" visibility="public" description=""/>
<conf name="sources" visibility="public" description=""/>
<conf name="docs" visibility="public" description=""/>
<conf name="pom" visibility="public" description=""/>
</configurations>
<publications>
<artifact name="akka_2.9.2" type="pom" ext="pom" conf="pom"/>
<artifact name="akka_2.9.2" type="jar" ext="jar" conf="compile"/>
<artifact name="akka_2.9.2" type="src" ext="jar" conf="sources" e:classifier="sources"/>
<artifact name="akka_2.9.2" type="doc" ext="jar" conf="docs" e:classifier="javadoc"/>
</publications>
<dependencies>
<dependency org="org.scala-lang" name="scala-library" rev="2.9.2" conf="compile->default(compile)"/>
<dependency org="com.typesafe.akka" name="akka-actor" rev="2.0.1" conf="compile->default(compile)"/>
<exclude org="org.scala-lang" module="scala-library" artifact="*" type="jar" ext="*" matcher="exact"/>
<exclude org="org.scala-lang" module="scala-compiler" artifact="*" type="jar" ext="*" matcher="exact"/>
<override org="org.scala-lang" module="scala-library" matcher="exact" rev="2.9.2"/>
<override org="org.scala-lang" module="scala-compiler" matcher="exact" rev="2.9.2"/>
</dependencies>
</ivy-module>
I'm new to Ivy, so this doesn't tell me much. I just figure that it mentions sources and javadocs, but somehow the IvyDE doesn't pick it up.
You can put
EclipseKeys.withSource := true
to your build.sbt, which lets sbteclipse download all sources and makes them accessible within Eclipse. Note, this will download all sources from all configured dependencies. I have no idea how to tell sbt to download only the sources for single dependencies.
Finally I found a solution to let sbt download the sources and tell Eclipse where to find them.
Add in build.sbt:
EclipseKeys.withSource := true
Then run:
rm -rf ~/.ivy2/cache/
sbt update-classifiers
sbt eclipse
The weird part is that if you already downloaded the dependencies in ivy, you have them in cache and you won't be able to download the sources for them.
I managed to get this working finally.
I had to use an external ivy settings file:
<ivysettings>
<properties environment="env" />
<settings defaultResolver="play" defaultResolveMode="dynamic" />
<caches defaultCacheDir="${env.PLAY_HOME}/repository/cache" />
<resolvers>
<chain name="play">
<ibiblio name="typesafe-releases" m2compatible="true" root="http://repo.typesafe.com/typesafe/releases" />
<ibiblio name="sonatype-oss-releases" m2compatible="true" root="http://oss.sonatype.org/content/repositories/releases" />
<filesystem name="local-filesystem">
<ivy pattern="${env.PLAY_HOME}/repository/local/[organization]/[module]/[revision]/ivys/ivy.xml" />
<artifact pattern="${env.PLAY_HOME}/repository/local/[organization]/[module]/[revision]/[type]s/[module](-[classifier]).[ext]" />
</filesystem>
<ibiblio name="central-uk" m2compatible="true" root="http://uk.maven.org/maven2" />
<ibiblio name="typesafe-snapshots" m2compatible="true" root="http://repo.typesafe.com/typesafe/snapshots" />
<ibiblio name="sonatype-oss-snapshots" m2compatible="true" root="http://oss.sonatype.org/content/repositories/snapshots" />
</chain>
</resolvers>
</ivysettings>
And add:
externalIvySettings(baseDirectory(_ / "ivysettings.xml"))
to my Build.scala.
The order of the resolvers in the chain proved to be important, because if Ivy finds a jar but no sources it won't check the other resolvers for sources/javadoc. The repository in the local Play install doesn't have sources or javadoc in.
This gets me source attachments for most of the jars in my dependencies when IvyDE resolves in Eclipse.
I find that it's easier to give IvyDE and sbt different ivy cache directories. Yes, it takes more space, but sbt by default doesn't download sources. And once sbt has loaded the cache without sources, IvyDE won't add them. You can tell sbt to fetch them, but for me it's easier just to use more disk space and use two different caches.
I do this by leaving sbt at the default, and setting IvyDE to use this file in Preferences > Ivy > Settings tab > Ivy settings file:
<ivysettings>
<settings defaultResolver="nexus" />
<property
name="nexus-public"
value="http://localhost:8081/nexus/content/groups/public" />
<resolvers>
<ibiblio
name="nexus"
m2compatible="true"
root="${nexus-public}" />
</resolvers>
<caches defaultCacheDir="${user.home}/.ivy2eclipse" />
</ivysettings>
That points to my local nexus server, so'll you'll need to modify it for your environment.
Well, I have given up on this and returned to NetBeans 7.1.2 + Scala plugin + Maven. This combination is much better integrated and works out of the box without tinkering.
When I work on small desktop projects I used to create lib folder in my project's root where I keep all project's jar dependencies. Then I use Configure Build Path -> Libraries -> Add JARs... to manually add all jars from this folder to buildpath/classpath. And because Add JARs... (unlike Add external JARs) uses relative paths, the project is portable, what is important for me.
The problem is that each time I add or remove a jar from my lib folder I need to manually add/remove this jar in project buildpath settings (and of course I often forget to do so).
Is there a way to just inform Eclipse that "This is a folder where I keep all of my jars. Please, add all the jars from there automatically to buildpath/classpath"? I tried to treat this folder as a class folder (Add class folder...) but it doesn't work that way :(.
P.S. I know about Maven and Eclipse-Maven integration but I want to keep my small project's simple (Maven integration is sometimes frustrating so I prefer to avoid it in these projects), so please don't suggest this in answer. Also as I mentioned, these are desktop projects, so there is no WEB-INF/lib folder in my project that is usually automatically handled by Java EE plugins.
you can try with a classpath container, take a look here for an example .
Take a look also at the Apache IvyDE classpath container .
However adding a new library to the classpath is simple and quick as :
Right click on it ---> Build Path ---> Add To Build Path
EDIT
This lightweight plugin should do exactly what you want !
I am not too sure, but can't you have wildcards in your classpath? That way you could just edit your .classpath file for that Eclipse project and use * within a particular folder... I have not tried, i'm in a rush but that's my idea... don't know if works
EDIT here is something that you could find useful:
How to use a wildcard in the classpath to add multiple jars?
Basically, just edit your .classpath file, which is where Eclipse stores the classpath settings for a project
I think the best is to use Gradle. This does not have the frustration of Maven with Eclipse. If you use STS it comes with Gradle pre-bundled.
See the link
So yeah I did this before:
Use Apache Ant and specify an ant configuration that suits your build path and eclipse should be able to use it with the use from existing ant build option.
Here is an example ant file you might have:
<?xml version="1.0"?>
<project name="Demo Project" basedir="." default="package">
<!-- ================================================================= -->
<!-- C O N F I G U R A T I O N -->
<!-- ================================================================= -->
<!--
Access the environment properties
-->
<property environment="env" />
<!--
TODO: Access the environment properties with a prefix of "env".
-->
<!--
Additional 3rd-party tools
-->
<property name="ant.home" value="${env.ANT_HOME}"/>
<property name="junit.home" value="${env.JUNIT_HOME}"/>
<property name="jmock.home" value="${env.JMOCK_HOME}"/>
<!--
Project folders
-->
<property name="project.home" value="${basedir}" />
<property name="bin.dir" value="${project.home}/bin" />
<property name="dist.dir" value="${project.home}/dist" />
<property name="dist.file" value="${dist.dir}/lab03.jar" />
<property name="col.file" value="${dist.dir}/lab03-col.jar" />
<property name="src.dir" value="${project.home}/src" />
<property name="lib.dir" value="${project.home}/lib" />
<!--
TODO: Define the classpath to be used during compilation. This should
consist of all of the JAR files in the ${lib.dir} folder.
-->
<path id="project.class.path">
<path location="${dist.file}" />
<path location="${bin.dir}" />
<fileset dir="${junit.home}">
<include name="junit-4.7.jar"/>
</fileset>
<fileset dir="${jmock.home}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${ant.home}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!--
TODO: Define the classpath to be used during execution. This should
consist of all of the JAR files in the ${lib.dir} folder as well as
${dist.file}.
-->
<path id="execution.class.path">
<path location="${bin.dir}" />
<path location="${bin.dir}/MyPath1/MyPath" />
<path location="${bin.dir}/MyPath1/MyPath/impl" />
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- ================================================================= -->
<!-- C L E A N -->
<!-- ================================================================= -->
<target name="clean"
description="Clean all build products">
<delete dir="${bin.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- ================================================================= -->
<!-- C O M P I L E -->
<!-- ================================================================= -->
<target name="compile"
depends="clean,init"
description="Compiles the application code">
<!--
TODO: Add the javac task. It should compile everything in ${src.dir}
and place the output in ${bin.dir}. The classpath should refer to the
"project.class.path" defined above.
-->
<javac srcdir="${src.dir}"
destdir="${bin.dir}">
<classpath refid="project.class.path" />
</javac>
</target>
<!-- ================================================================= -->
<!-- E N V -->
<!-- ================================================================= -->
<target name="env"
description="Displays information about the build">
<echo message="src.dir..........${src.dir}" />
<echo message="lib.dir..........${lib.dir}" />
<echo message="bin.dir..........${bin.dir}" />
<echo message="dist.dir.........${dist.dir}" />
<echo message="dist.file........${dist.file}" />
<echo message="col.file.........${col.file}" />
<echo message="reports.dir......${reports.dir}" />
</target>
<!-- ================================================================= -->
<!-- I N I T -->
<!-- ================================================================= -->
<target name="init"
depends="env"
description="Initializes the environment">
<mkdir dir="${bin.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- ================================================================= -->
<!-- P A C K A G E -->
<!-- ================================================================= -->
<target name="package"
depends="compile"
description="Creates the application distribution file">
<!--
TODO: Create a JAR file. The target JAR should be ${dist.file} and it
should contain everything from ${bin.dir}.
-->
<jar destfile="${dist.file}"
basedir="${bin.dir}"
excludes="**/*Test*.class"
/>
</target>
<!-- ================================================================= -->
<!-- P A C K A G E - C O L -->
<!-- ================================================================= -->
<target name="package-col"
depends="compile"
description="Creates the file to be submitted to COL.">
<jar destfile="${col.file}">
<fileset dir="${project.home}"
includes="src/**/*.java" />
<fileset dir="${project.home}"
includes="lib/**/*.jar" />
<fileset dir="${project.home}"
includes="build.xml" />
</jar>
</target>
<!-- ================================================================= -->
<!-- R U N -->
<!-- ================================================================= -->
<target name="run"
depends="package"
description="Executes the test file">
<java classname="MyPath1.MyPath.FileScanner">
<classpath refid="execution.class.path" />
<arg value="file:///" />
</java>
</target>
</project>
AND Here is a link with someone with a similair problem using ant to solve his classpath problems.
Ant is portable so it can actually be set up anywhere and you can also use global variables to keep all systems consistent or just use relative paths. And there is also an eclipse ant plugin
just try including
<classpathentry kind="lib" path="lib/spring/4.2.1" including="*.jar"/>
I need to use XML to JSON lib in my war.
I followed a tutorial explaining that dependencies are required in the project.
But when I add the following in my ant build.xml (the file used to create the war), Eclipse complains about the artifact:dependencies, seems like it does not like the :.I have the following error message:
The prefix artifact for element artifact:dependencies is not bound...
<artifact:dependencies filesetId="dependency.fileset"
sourcesFilesetId="sources.dependency.fileset"
javadocFilesetId="javadoc.dependency.fileset"
versionsId="dependency.versions">
<!-- DEPENCIES GO HERE -->
</artifact:dependencies>
Any idea ?
UPDATE
I have the same problem trying to define an in-memory pom with:
<artifact:pom id="mypom" groupId="org.acme" artifactId="project1" version="1.0">
<dependency groupId="junit" artifactId="junit" version="4.1"/>
<dependency groupId="org.codehaus.plexus" artifactId="plexus-utils" version="1.5.5"/>
<license name="apache" url="http://www.apache.org"/>
</artifact:pom>
The prefix artifact for element artifact:pom is not bound...
UPDATE 2
I installed maven-ant jar in ant/lib and change the build.xml so it contains the definition of the artifact stuff but I have an error message while running it.
<project name="test" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<artifact:dependencies pathId="dependency.classpath">
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
...
The error message Eclipse gave is:
BUILD FAILED
D:\J2EE\workspace\Test\build.xml:3: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:dependencies
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
-C:\Documents and Settings\luc\.ant\lib
-a directory added on the command line with the -lib argument
The maven-ant jar does exist in -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
UPDATE 3
This is the build.xml file I'm using.
<!--
<project name="Monitoring" default="install" xmlns:artifact="urn:maven-artifact-ant" xmlns:test="urn:test-tasks">
-->
<project name="Monitoring" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- project-specific variables -->
<property environment="env" />
<property name="project_home" value="D:\J2EE\workspace\Monitoring"/>
<property name="webapp.dir" value="${project_home}/target" />
<property name="jboss.dir" value="D:\J2EE\jboss\standalone\deployments" />
<property name="package.name" value="monitoring.war" />
<property name="lib.dir" value="${project_home}/lib" />
<property name="src.dir" value="${project_home}/src" />
<property name="resources.dir" value="${project_home}/resources" />
<property name="dest.dir" value="${project_home}/target" />
<property name="package.file" value="${dest.dir}/${package.name}" />
<!-- put everything in a temp folder with the right structure during the build -->
<property name="temp.dir" value="${project_home}/temp" />
<property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" />
<path id="build.class.path">
<fileset dir="${env.JAVA_HOME}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="D:\ant\lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="deps">
<artifact:dependencies pathId="dependency.classpath">
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.1</version>
</dependency>
</artifact:dependencies>
</target>
<target name="clean" depends="deps">
<delete>
<fileset dir="${dest.dir}" includes="**/*"/>
</delete>
<delete dir="${temp.dir}" />
<delete dir="${temp.dir.classes}" />
<delete dir="${temp.dir.meta-inf}" />
<delete dir="${temp.dir.web-inf}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${dest.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${temp.dir.lib}" />
<mkdir dir="${temp.dir.meta-inf}" />
<mkdir dir="${temp.dir.web-inf}" />
<mkdir dir="${temp.dir.classes}" />
</target>
<!-- COMPILE -->
<target name="compile" depends="prepare">
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files ...</echo>
<javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}" includes="**/*" includeantruntime="false">
<classpath refid="build.class.path" />
<classpath refid="dependency.classpath" />
</javac>
</target>
<!-- PACKAGE -->
<target name="package" depends="compile">
<echo>=== PACKAGE ===</echo>
<!-- copy the config files -->
<copy file="${resources.dir}/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />
<copy file="${resources.dir}/manifest.mf" tofile="${temp.dir.meta-inf}/manifest.mf" overwrite="true" />
<copy todir="${temp.dir.classes}">
<fileset dir="${src.dir}">
<include name="**/*.xml"/>
<include name="**/*.xsl"/>
</fileset>
</copy>
<!-- the ant war task. with all resources in place, create the war file -->
<war destfile="${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">
<lib dir="${lib.dir}" />
<classes dir="${temp.dir.classes}" />
</war>
</target>
<!-- INSTALL -->
<target name="install" depends="package">
<echo>=== INSTALL ===</echo>
<copy file="${package.file}" tofile="${webapp.dir}/${package.name}" overwrite="true" />
<copy file="${package.file}" tofile="${jboss.dir}/${package.name}" overwrite="true" />
</target>
</project>
It was working well before I added all the dependencies stuff... still cannot find out the pb here. Any help would be very welcome.
It looks like you're making use of Maven Ant Tasks. To do this you'll need a copy of the jar from the download area here.
Once (or if) you've got that, you'll need to modify your buildfile to use it.
The main things that are needed are to define the artifact namespace, and add the typedef for the ant-lib:
<project name="foo" default="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
I had the same error message but the cause was different.
Going to Window -> Preferences -> Ant -> Runtime and setting Ant Home solved my problem.
So for anyone that above solution doesn't work, check if "Ant Home" is pointing to the right direction