How do I force Maven/Eclipse to download a JAR dependency? - eclipse

I'm using Maven 3.3.3, Java 8 on Windows 7. I"m using Eclipse Mars. I'm trying to run a JUnit test in my Eclipse editor by right clicking on the class name, selecting, "Run As" -> "JUnit Test", and I'm getting this error
The archive: C:/Users/myuser/.m2/repository/commons-fileupload/commons-fileupload/1.2/commons-fileupload-1.2.jar which is referenced by the classpath, does not exist.
I have this dependency in my project's pom.xml file
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
What is odd is that if I run the test directly from the command line (using bash shell on Cygwin), the test runs ...
$ mvn clean test -Dtest=MyControllerIT
Hoewver, when I look in my repository, there is no JAR file downloaded. All it has is
$ ls /cygdrive/c//Users/myuser/.m2/repository/commons-fileupload/commons-fileupload/1.2/
_remote.repositories commons-fileupload-1.2.pom.lastUpdated
commons-fileupload-1.2.pom commons-fileupload-1.2.pom.sha1
How do I force the downloads of these JARs, or at least, how do I get Eclipse to stop complaining and being such a baby?

After updating the POM.xml file, all you have to do is, right click and refresh the Maven Dependencies.

Related

Eclipse maven not adding dependencies

I am new to maven and am experiencing difficulties while trying to mavenise a Java project.
Setting:
IDE: Eclipse Oxygen.2 Release (4.7.2)
Java: 8
m2e: 1.8.2
What I did:
- copy-pasted the entire original java project and renamed it
- right-click in eclipse: Configure > Convert to Maven project
- in java build path, deletion of libraries import from original local lib repo. The build path shows the Maven Dependencies folder, with the only junit library.
- maven install => downloaded things in the user/.m2/repository/, but not all.
What does not work:
When I try to add a dependency right from a file:
,
nothing pops up in the artifact selection windows, even though there is a commons-logging/ folder in m2/repository
When I try to add the dependency manually in the pom.xml:
<dependency>
<groupId>org.kie.modules</groupId>
<artifactId>org-apache-commons-configuration-main</artifactId>
<version>6.5.0.Final</version>
<type>pom</type>
</dependency>
but the package resolution error still appears in the java file, and I get this warning after Maven install
`[WARNING] The POM for org.kie.modules:org-apache-commons-configuration-main:pom:6.5.0.Final is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details`
I did Maven Update project, eclipse project clean, nothing changes.
My goal for now is just that eclipse understands (at least for one library), that it has to take it from maven repository. I still have many other dependencies to solve (intra-project), but that will be the next step.
Thanks for your help.
The cause of the issue is stated in the warning message :
[WARNING] The POM for
org.kie.modules:org-apache-commons-configuration-main:pom:6.5.0.Final
is invalid, transitive dependencies (if any) will not be available,
enable debug logging for more details
It means that the pom.xml downloaded in your local maven repository exists but is not valid.
Delete the folder of the dependency downloaded in your local maven repository and try again.
If you still have the same problem, check that your central repository that provides the dependency provides also correctly the pom.xml for that.
You can do it by browsing the directory of the dependency from a web browser.
For example we can see that the maven central repository provides a valid pom :
http://central.maven.org/maven2/org/kie/modules/org-apache-commons-collections-main/6.5.0.Final/org-apache-commons-collections-main-6.5.0.Final.pom

How do I get Eclipse to respect the #FixMethodOrder JUnit directive?

I’m using Eclipse Kepler (Java 8). with my Maven (v 3.2.3) project. I’m using JUnit 4.11, as declared in my pom.xml file …
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
I’m trying to run some JUnit tests and I have this at the top of my tests
#FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MyTest
{
However, when I run the test in Eclipse (by right clicking the name of the file and selecting “Run As”, “JUnit Test”), Eclipse is not running the tests in ascending order by name, but instead running the tests one by one as they are listed in the file.
My question is, how can I get Eclipse to respect the “FixMethodOrder” directive in my file? Note that I’m not interested in lectures about why it shouldn’t matter what order you run JUnit tests in.
Open your project build path (right-click on project > Build Path > Configure Build Path...) and go to the Libraries tab. Do you have "JUnit 4" on your Eclipse classpath or just "Maven Dependencies":
Remove it by selecting "JUnit 4" and hitting the remove button to the right. Maven specifies all your dependencies so you don't need Eclipse adding to that.
In my experience Eclipse seems to prefer its own JUnit library at runtime over the JUnit library provided by "Maven Dependencies": I get different results in test execution order between Eclipse and direct Maven when using #FixMethodOrder if the Eclipse "JUnit 4" library is on the classpath, but if I remove that library then Eclipse and Maven are in agreement.

Eclipse cannot find class com.google.common.reflect.TypeToken?

My project which uses Dataflow compiles just fine using
mvn compile
However when I import my project into eclipse, eclipse is unable to build the project and gives the following error
The project was not built since its build path is incomplete.
Cannot find the class file for com.google.common.reflect.TypeToken.
Fix the build path then try building this project
Adding an explicit dependency on Guava to my pom file appears to have fixed the problem.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>[18.0,)</version>
</dependency>
By running
mvn dependency:tree -Dverbose -Dincludes=com.google.guava
I learned that I had several dependencies that were pulling in Guava so by adding an explicit dependency I was able to force maven to pull in a newer version.
However, I don't know why running 'mvn compile' on the command line worked.

How would you add maven to an existing GWT project in Eclipse with m2e installed?

The project has GWTQuery included. I'd like to have the pom.xml generated in the existing project so I can configure the build.
You can start with an empty pom.xml by defining your project attributes first and add your dependency to gwtquery
<dependency>
<groupId>com.googlecode.gwtquery</groupId>
<artifactId>gwtquery</artifactId>
<version>1.3.3</version>
</dependency>
Another way is to generate a new project using an archetype:
Step 1:
mvn archetype:generate
Step 2: choose 44, which at the time of writing means: 44: remote -> com.googlecode.gwtquery:gquery-archetype (This archetype generates a Gwt-2.5.0-rc1 project with all set to use GwtQuery and its plugins.)
Step 3: enter your project information
The best way I see is to create a new maven-ready project using gwtquery archetype and setting the same namespaces and module name that you use in your current project.
mvn archetype:generate -DarchetypeGroupId=com.googlecode.gwtquery \
-DarchetypeArtifactId=gquery-archetype \
-DarchetypeVersion=1.3.3 \
-DgroupId=com.mycompany \
-DartifactId=myproject \
-DprojectName=MyProject
Then import the maven project in eclipse (use m2e plugin) and check if it works (dev mode, tests, etc).
Copy all your source code from your src folder to the new project src/main/java, the same with your public stuff, .gwt.xml file, and tests.
And finally add your dependencies to your pom using the eclipse pom editor.
Note: The m2e feature of converting a normal eclipse project to maven needs a lot of work.

Maven not updating/downloading dependencies

I'm using Eclipse EE and Apache Wicket.
I have my dependencies written down at pom.xml.
For some reason, maven is not updating even when I try to clean the project and go under Maven > Update Project.
When I go to check the dependencies the jar is there, but it still give me error when I try to run (ClassNotFoundException).
Why is this happening?
Dependency in question:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.3</version>
</dependency>
Also already tried to reinstall maven.
Try running mvn eclipse:eclipse to update ur Eclipse.
Also, refresh after completion of the command run.
You shouldn't mix "mvn eclipse:eclipse" and m2eclipse maven eclipse plugin, it will cause the plugin to not operate correctly. If you have done so, you need to remove your .project/.classpath/.settings files and re-import with "import existing maven projects".