尝试重建maven项目时出错

时间:2012-12-14 13:02:30

标签: java maven boofcv

我是maven的新人并且有这样的疑问。 我知道maven在C:\“User”\ m2文件夹中创建了它的本地存储库 当我创建我的项目(例如在eclipse中)并添加依赖项时。 然后我将我的M2_Home存储库添加到构建路径(C:\“User”\ m2)。

完成所有这些操作后,我打开命令行并编写mvn package。 Maven创建jar文件我启动它,一切看起来都很好。

但有时我在电脑上工作而且我没有管理员规则,也无法在磁盘C上创建文件夹:

唯一的解决方案是更改本地repo文件夹。我这样做并试图重建我在家里写的项目。 Maven在命令行中向我展示了所有构建都是成功的。 我启动jar文件,看到错误,告诉我我的应用程序找不到库(但是当我检查本地repo文件夹时,我发现这个库)。

有人可以帮助我解决这类问题。

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)

这是我的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>

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>

2 个答案:

答案 0 :(得分:2)

您创建的jar不包含您需要的依赖项。在这种情况下,您需要创建一个所谓的ueber-jar,可以使用maven-assembly-plugin (jar-with-dependencies)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>

答案 1 :(得分:2)

我更喜欢maven-shade-plugin而不是maven-assembly-plugin。 他们做了几乎相同的事情,但maven-assembly-plugin是错误的。

maven-assembly-plugin习惯于覆盖文件,这会导致丢失文件或其内容。

maven-shade-plugin只需添加它们即可解决此问题。