2016-12-03 35 views
1

使用maven-裝配插件中從開始,我可以使用命令獨立JAR行爲不同IDE

$ mvn clean compile assembly:single 

管束我的Java Web應用程序到一個單一的standalone.jar

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <mainClass>my.package.Main</mainClass> 
        </manifest> 
       </archive> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <finalName>standalone</finalName> 
       <appendAssemblyId>false</appendAssemblyId> 
      </configuration> 
     </plugin> 

比時應用程序是基於灰熊和澤西島的REST後端。 我可以用

$ java -jar standalone.jar 

啓動它,它似乎工作。控制檯輸出告訴我,HTTP服務器已啓動,現在正在偵聽端口8765.

不幸的是,當我向任何REST端點發送請求時,我收到錯誤代碼爲500的內部服務器錯誤的響應。 正如我可以從輸出得出結論,沒有任何請求處理方法被調用。

如果應用程序是從IDE IntelliJ(通過按運行按鈕)啓動的,則該應用程序可以正常工作。

類似的問題,有人問Java JAR behaving differently to program run out of IDE但在我的情況下,標誌-Dfile.encoding = UTF-8,也由IDE設置不能解決問題

編輯

至於建議中評論,我試圖檢查日誌輸出。我是按照Grizzly Standalone Logging

描述當我運行從最優秀的日誌記錄級別的IDE的應用程序,我收到了很多其他消息包括異常的方法

Dez 03, 2016 11:36:07 PM org.glassfish.jersey.internal.util.ReflectionHelper$2 run 
FINER: Unable to load class org.osgi.framework.BundleReference using the current class loader. 
java.lang.ClassNotFoundException: org.osgi.framework.BundleReference 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:264) 
    at org.glassfish.jersey.internal.util.ReflectionHelper$2.run(ReflectionHelper.java:262) 
    at org.glassfish.jersey.internal.util.ReflectionHelper$2.run(ReflectionHelper.java:247) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at org.glassfish.jersey.internal.util.ReflectionHelper.<clinit>(ReflectionHelper.java:1471) 
    at org.glassfish.jersey.server.ResourceConfig$State.<init>(ResourceConfig.java:112) 
    at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:353) 
    at my.package.Main.main(Main.java:42) 

我沒有得到任何額外的記錄消息時,我執行standalone.jar與-Djava.util.logging.config.file = ...

+0

應該有一些有關服務器的日誌文件中的錯誤。你看了?如果是的話,沒有什麼,你試圖增加日誌記錄級別? –

回答

0

我懷疑你的罐子已經打包帶內它打包所有需要的依賴條件。首先檢查造成的類org.osgi.framework.BundleReference是否實際包含在您的jar中。

如果沒有,我想有什麼東西在你的POM中失蹤。包括simple目標執行到您的程序集插件定義並再次運行Maven:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>3.0.0</version> 
    <configuration> 
     ... 
    </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> 

documentation