2012-12-14 210 views
2

我是新手,有這樣的問題。 我知道maven在C:\「User \」文件夾下創建它的本地資源文件夾 ,當我創建我的項目(例如在eclipse中)並添加依賴關係時。 然後我將我的M2_Home存儲庫添加到構建路徑(C:\「User」\ m2)中。嘗試重建maven項目時出錯

經過這一切操作,我打開我的命令行並編寫mvn package。 Maven創建jar文件我開始它,一切看起來很好。

但有些時候我在電腦工作,我也沒有管理員的規則並不能在磁盤上創建文件夾C:

唯一的解決辦法是改變本地回購文件夾。我這樣做,並試圖重建我在家寫的項目。 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> 
+0

如果您使用maven,則不應將m2路徑添加到您的構建路徑,因爲這是由Maven處理的。你是否在使用m2e Plugin for Eclipse? – khmarbaise

+0

是的,我使用m2e插件 –

+0

如果您是本地管理員權限無關緊要嗎? Maven在您自己的用戶目錄中寫入您有權這樣做的權限。你能更具體地說明你運行的是什麼命令,你改變了什麼,報告的錯誤是什麼? – Hugo

回答

2

您已經創建了不包含罐子你需要的依賴關係。在這種情況下,你需要創建一個所謂的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> 
2

我喜歡maven-shade-pluginmaven-assembly-plugin來完成。 他們做幾乎相同的事情,但maven-assembly-plugin是越野車。

maven-assembly-plugin有一個覆蓋文件的習慣,這會造成文件或其內容的丟失。

maven-shade-plugin通過簡單地附加它們來解決這個問題。