2

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

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

但有时我在计算机上工作,我没有管理员规则,无法在磁盘 C 上创建文件夹:

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

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

更新2 在此处输入图像描述

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>
4

2 回答 2

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>
于 2012-12-14T13:21:57.313 回答
2

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

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

maven-shade-plugin通过简单地附加它们来解决这个问题。

于 2012-12-14T13:46:23.857 回答