I have an ivy dependency management to work both under eclipse and with ant.
How should I configure the test dependencies to be available for eclipse?
my current configuration is:
<configurations>
...
<conf name="test" visibility="public"/>
</configurations>
<dependencies>
...
<dependency org="org.testng" name="testng" rev="6.7" conf="test->provided" transitive="false"/>
</dependencies>
With that configuration TestNG is not "retrieved". I'm using IvyDE, and 'Select every configuration' is set.
Related
Can anyone tell me how I can get a profile to be picked up when running a web project from inside eclipse. This is my latest attempt, which does not work (file-dev.xml not parsed). I have a war project which has a dependency on a jar project. Th jar project contains the spring beans.
in pom.xml of jar project:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<env>uat</env>
</properties>
</profile>
</profiles>
Also in the pom, I have added this to the maven-jar-plugin
<configuration>
<argLine>-Dspring.profiles.active=dev</argLine>
</configuration>
in spring config xml file:
<import resource="file.xml" />
in file.xml
<import resource="file-dev.xml" />
in file-dev.xml
<beans profile="dev">
<bean id="myBean"> etc etc </myBean>
</beans>
running mvn help:active-profiles returns " - dev"
Any idea what I cma missing? I have not tried any maven build or install yet, I just want it working in the dev environment, so we can deploy to tomcat from within eclipse first.
Thanks in advance
I'm using Eclipse Kepler SR2 with m2e.
I have a web project that depends on a jar.
When I use "Run as -> Maven Build..." with goal package and "Check Workspace artifacts" is checked, then the lib folder in the target contains a folder with the name of the dependency jar, instead of the jar itself. The packaged war also contains a folder instead of a jar. However, when deploying to tomcat with m2e, the jar is deployed correctly.
I use maven-war-plugin version 2.4.
This is my WAR pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
</project>
And this is the artifact coordinates of the dependency jar:
<parent>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-core</artifactId>
<packaging>jar</packaging>
I've looked at the debug output of the maven package goal. When the war plugin is processing the jars, it says
[DEBUG] Processing: loans-core-0.0.1-SNAPSHOT.jar
without indicating the jar has been copied.
Later on in the log I see:
adding directory WEB-INF/lib/loans-core-0.0.1-SNAPSHOT.jar/
I've tried both embedded maven (3.0.4) and external maven (3.0.5).
My colleague uses kepler SR1, and experience the same problem.
I think I've covered it all. Would be happy for some advise, couldn't find any reported bug about it.
Thanks,
Lior
Try installing the jar as its own maven-controlled artifact:
mvn install:install-file -Dfile=my.jar -DgroupId=com.mycorp -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
And then define it as a maven dependency for your war
now we have 2018 and the problem still exists in eclipse v2018-09. Maven Dependencies which exist in the workspace are exploded into WEB-INF/lib folder.
Found this old bug report https://issues.jboss.org/browse/JBIDE-22157 regarding this behaviour.
Solution is to disable "dependency resolution from workspace projects" in maven project settings.
regards,
Markus
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.
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.
I'm using Eclipse 3.5, Maven 2, m2eclipse and Tomcat 6. So i create Maven project for archetype webapp.
This is pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itransition</groupId>
<artifactId>hello</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>hello Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- tools.jar dependency -->
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8.1</version>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
</build>
</project>
So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.
This problem can be resolved by using the Tomcat plugin for Maven. Its homepage has got extensive documentation concerning the configuration of the plugin and deployment of war files.
It can be done in 2 ways.
Refer below URL
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
Create maven Project with eclipse and locate the project folder from command prompt (or) Terminal
mvn eclipse:eclipse -Dwtpversion=2.0 [ in project folder ]
Refersh Eclipse project.
Now you can Add and Remove Deployment.
Found out that the tomcat manager url (i am using Tomcat 6.0) is http://localhost:8080/manager/html, while the default used by the mvn tomcat plugin stops at manager in the URL. Add the url specified to your pom.xml as a configuration parameter - (see this url for more details http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html) and voilĂ it works...
With Tomcat7, I found I needed to set up the URL as http://localhost:8080/manager/html and use a username with a manager-gui role. However, using a username with the manager-script role, with URL http://localhost:8080/manager/text also works and is more appropriate. The manager-script role is the designed way to go for ant/maven scripts.
So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.
Since you are using m2eclipse, my recommendation would be to deploy your application using the WTP. Assuming you have the Maven integration for WTP feature installed (from m2eclipse extras) and Tomcat configured as Server, just right-click on your project and select Run > Run on Server...
Another option would be to run your application on Jetty (yes, I know that this is not what you're asking for but this is very valid option if you don't want to use the WTP). Add the following snippet to your pom:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
</plugins>
</build>
</project>
And simply run mvn jetty:run to start an embedded Jetty server and deploy your application on it.
The same can be achieved for Tomcat using the Tomcat Maven Plugin but unless you want to deploy to a remote Tomcat (see the Usage page), I don't see any advantage over the Maven Jetty Plugin.
During development, I would use the first option (deploy with the WTP).
If you want that your war file created by maven, should be deploy on tomcat server directly then this tomcat deployment configuration can help you.