2

I'm new in maven and have such question. I know that maven creates it's local repository in C:\"User"\m2 folder and when I create my project(for example in eclipse) and add dependencies. Then I add my M2_Home repository into build path (C:\"User"\m2).

After all this operations I open my command line and write mvn package. Maven creates jar file I start it and all looks fine.

but some times I work at the computers and I have not administrator rules and can't create folder on disk C:

The only solution is to change local repo folder. I do this and trying to rebuild project that I write at home. Maven shows me in command line that all build were success. I start jar file and see error which told me that my app can't find library (but when I check local repo folder I find this libs).

So can someone help me to solve such kinds of problems.

UPDATE2 enter image description here

E:\ColorCorrectLab\target>java -jar ColorCorrectLab2-1.0.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: boofcv/gui/feature/AssociationPanel
        at by.bulgak.colorcorrection.menubar.ImageFilterMenuBar$1.actionPerformed(ImageFilterMenuBar.java:87)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$200(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: boofcv.gui.feature.AssociationPanel
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

This is my 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ColorCorrectLab2</groupId>
    <artifactId>ColorCorrectLab2</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>org.boofcv</groupId>
            <artifactId>boofcv</artifactId>
            <version>0.12</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>by.bulgak.colorcorrection.main.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

at http://boofcv.org/index.php?title=Download:BoofCV

 Maven

BoofCV is on Maven central repository. To add it to your project add the following to your project's pom file:

<dependency>
  <groupId>org.boofcv</groupId>
  <artifactId>boofcv</artifactId>
  <version>XXX</version>
</dependency>
Rui Marques
  • 8,567
  • 3
  • 60
  • 91
Aliaksei Bulhak
  • 6,078
  • 8
  • 45
  • 75
  • If you use maven you shouldn't need to add the m2 path to your build path cause this is handled by Maven. Are you using m2e Plugin for Eclipse ? – khmarbaise Dec 14 '12 at 13:04
  • It does not matter if you're local administrator right? Maven writes in your own user directory where you have rights to do so. Could you be more specific on what commands you run, what you changed and what the reported errors are? – Hugo Dec 14 '12 at 13:08
  • one minute please I make new screenshots – Aliaksei Bulhak Dec 14 '12 at 13:09
  • Please post text instead of images; cut-and-paste *is* your friend in this case. – Dave Newton Dec 14 '12 at 13:17
  • The jar you have created dosn't contain the dependencies you need. In this case you need to create a so called **ueber-jar** which can be accomplished by using maven-assembly-plugin (jar-with-dependencies) or via the maven-shade-plugin. – khmarbaise Dec 14 '12 at 13:19
  • my pom file contains all important dependencies. When I start mvn package and then start jar at work all warks fine – Aliaksei Bulhak Dec 14 '12 at 13:22

2 Answers2

2

The jar you have created doesn't contain the dependencies you need. In this case you need to create a so called ueber-jar which can be accomplished by using maven-assembly-plugin (jar-with-dependencies) or via the maven-shade-plugin

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
2

I prefer maven-shade-plugin over maven-assembly-plugin. They do almost same thing but maven-assembly-plugin is buggy.

maven-assembly-plugin has a habit of overwriting files which will create lose of files or their contents.

maven-shade-plugin solve this problem by simply appending them.

Mawia
  • 4,220
  • 13
  • 40
  • 55