0

When I run

mvn compile

I get package com.ibm.icu.util does not exist. So I downloaded the ICU4J jar and installed it into the local repository. I confirmed it's in .m2/repository/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar. Inside that jar file is the missing class file com/ibm/icu/util/Calendar.class. Then I added the following into the dependencies section of pom.xml:

<dependency>
   <groupId>com.ibm.icu</groupId>
   <artifactId>icu4j</artifactId>
   <version>3.4.4</version>
</dependency>

But when I run mvn compile again, I get the same error. What am I doing wrong?

dimo414
  • 47,227
  • 18
  • 148
  • 244
user3217883
  • 1,216
  • 4
  • 38
  • 65
  • (1) Why the ancient version? (2) Why aren't you resolving this from Central? – chrylis -cautiouslyoptimistic- Jun 27 '15 at 01:43
  • Have you tried `mvn clean`? Or blowing out you're `repository` directory and allowing maven to redownload everything. You shouldn't have to manually add a jar, certainly a sign that something is out of sync. – Sam Berry Jun 27 '15 at 01:56
  • mvn clean is what got me into this error. it was working before I did that. I can't download because it's compiling on a remote server that doesn't have internet connection. – user3217883 Jun 27 '15 at 02:09
  • Sam B. - I finally got it working by blowing away the local repository, running mvn package -DskipTests on my local windows box (which does have internet access), an copying that repository over to the remote linux server. Then mvn also worked on the remote server. Thanks to all for your time and suggestions! – user3217883 Jun 27 '15 at 22:01

3 Answers3

1

You should avoid adding dependencies manually.

If you don't know a groupId and artifactId of the dependency you need, search for it at http://mvnrepository.com/. Usually, groupId matches the package names in the jar file.

For your case, the dependency is already there: http://mvnrepository.com/search?q=com.ibm.icu So, go to http://mvnrepository.com/artifact/com.ibm.icu/icu4j and get the version of the dependency you need, e.g. 55.1: http://mvnrepository.com/artifact/com.ibm.icu/icu4j/55.1 Grab maven dependency xml and put it to your pom.xml file:

<dependency>
    <groupId>com.ibm.icu</groupId>
    <artifactId>icu4j</artifactId>
    <version>55.1</version>
</dependency>

If you didn't find your dependency try to find it in google. Sometimes the dependency may be found in some corporate public repositories, not in a central. In this case you need to add the third-party repository to repositories section of your pom.xml.


If you're unable to find your dependency in the public repository then you have three options:

A. Install jar to internal repository server (e.g. nexus)

B. Put the JAR file in your project sources and declare project maven repository :

<repositories>
    <repository>
        <id>my-local-repo</id>
        <url>file://${basedir}/my-repo</url>
    </repository>
</repositories>

Important: You should keep the maven repository layout in your local repository.

C. [Bad Practice] Use maven install plugin to install your custom jar to local repository on your machine. But it's a badIt's not recommended.

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to-your-artifact-jar -DpomFile=path-to-pom

D. [Bad Practice] Use system dependency with absolute path to the JAR file, although it's a bad practice and should be avoided.

<dependency>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>X.Y.Z</version>
  <scope>system</scope>
  <systemPath>${user.home}/jars/my.jar</systemPath>
</dependency>
Community
  • 1
  • 1
Konstantin Pavlov
  • 956
  • 1
  • 10
  • 24
  • I'll try the local repository thing but it doesn't make sense to me why what I did doesn't work this time, like it did 149 other times. – user3217883 Jun 27 '15 at 18:00
  • I created a local repository here: /export/home/ripper/maven/repository and installed icu4j-2.6.1.jar to it. Also installed the associated .pom file. Added the repository tag to the main pom.xml. Result: same error! – user3217883 Jun 27 '15 at 18:45
  • You should keep maven repository structure in your local repository. For your case you should have two files: `/export/home/ripper/maven/repository/com/ibm/icu/icu4j/55.1/icu4j-55.1.jar` and `/export/home/ripper/maven/repository/com/ibm/icu/icu4j/55.1/icu4j-55.1.pom` – Konstantin Pavlov Jun 27 '15 at 20:11
0

You should not be manually installing things into the maven repository directory. That directory is maintained by maven itself.

The way dependencies work is that when you run mvn compile or some other goal, it will connect to the maven central repository and download the needed dependencies and their dependencies.

If you manually install a jar file, it may not have it's dependencies. That icu artifact will likely have other things it depends on. Maven will automatically resolve these dependencies.

I would recommend using mvn clean install this will clean the target directory and rebuild everything.

If it fails to download, then you likely need to change the maven configuration. For example, if you are behind a proxy server you need to configure maven with the proxy credentials.

Also, if you manually copied anything into the .m2/repository/ directory you should delete it and let maven put it in there correctly instead.

The beauty of maven is that you don't need to worry about things like downloading jars. It just handles that for you. Let it do it's job.

Jon
  • 3,212
  • 32
  • 35
  • I tried your suggestion mvn clean install, however got the same error. I wish I could let maven do its job but unfortunately, the remote server I'm building on is in a proprietary intranet not connected to the internet so maven cannot download any files. I had to manually download and install 300 files to get this to work. It's a mystery to me why the clean would cause it to stop working. It only cleans out the target folders right? – user3217883 Jun 27 '15 at 03:31
  • The fact that you manually downloaded 300 files means something is wrong with your maven configuration or the way you are using maven. Perhaps you should try renaming your repository and letting Maven recreate a new one itself. – Jon Jun 27 '15 at 23:15
  • Clean only cleans the target directory. It doesn't mess with the repository directory. As far as I know, there are no commands to clean anything in the repository. This is because maven does not expect you to mess with those directories. They are meant to be managed by it. If your repository is corrupted, try my suggestion above. – Jon Jun 27 '15 at 23:19
  • I still don't know that I did anything wrong, I still don't know why mvn clean caused it to stop working. But apparently there was something wrong with the .m2/repository since blowing it away and restoring it from another machine that had internet connection worked. I'll give you the credit. – user3217883 Jun 28 '15 at 21:26
0

If you have an internal artifactory like JFrog maybe you should check that the jar is there. Do not download manually to .m2 because it's at least strange. At most you can upload the jar in that artifactory manually.

Daniel Jipa
  • 878
  • 11
  • 24