2

maven プロジェクト以外のどこかでファット jar を実行しようとしています。実行可能な jar は eclipse から作成されます ([エクスポート] -> [実行可能な jar] -> [生成された jar に必要なライブラリを抽出])。このjarには、lib内のすべての依存関係jarと外部jar、およびクラスファイルがあります。

Eclipse の Maven 依存関係のスナップショット --> Maven 依存関係

以下は、次のように配置された実行可能なjarの構造ですE:/JAR/fatFromEclipse.jar

META-INF/maven/
META-INF/maven/commons-net/
META-INF/maven/commons-net/commons-net/
META-INF/maven/commons-net/commons-net/pom.xml
META-INF/maven/commons-net/commons-net/pom.properties
META-INF/eclipse.inf
META-INF/services/
META-INF/services/javax.tools.JavaCompiler
META-INF/services/javax.servlet.ServletContainerInitializer
META-INF/web-fragment.xml
META-INF/eclipse.inf
META-INF/services/
META-INF/services/javax.tools.JavaCompiler
about.html
ecj.1

WEB-INF/
WEB-INF/lib/
WEB-INF/lib/commons-io-1.2.jar
WEB-INF/lib/commons-net-3.5.jar
WEB-INF/lib/gson-2.2.2.jar

webapp/
webapp/META-INF/
webapp/META-INF/MANIFEST.MF
webapp/WEB-INF/
webapp/WEB-INF/web.xml
webapp/images/
webapp/images/ajax-loader.gif
webapp/images/ajax-loader2.gif
webapp/images/ajax-loader3.gif
webapp/images/ajax-loader4.gif
webapp/jsp/
webapp/jsp/Archive.jsp

com/SBMArchievePurge/App.class

....
and depedencies class files
..

以下は、実行可能なjarから実行されるメインクラスです。

 String contextPath = "/";
 String appBase = "webapp/";  

 Tomcat tomcat = new Tomcat();     
 tomcat.setPort(8081);
 tomcat.getHost().setAppBase(appBase);

 String path=null;
String decodedPath=null;
 try {
    path=App.class.getProtectionDomain().getCodeSource().getLocation().getPath();

    decodedPath = URLDecoder.decode(path, "UTF-8");
        System.out.println("path of Main==>"+decodedPath);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

 ClassLoader cl= App.class. getClassLoader();

 System.out.println("0===>"+cl.getResource("webapp/" ));
 System.out.println("1 getPath===>"+cl.getResource("webapp/").getPath());
 System.out.println("2 toExternalForm===>"+cl.getResource("webapp/").toExternalForm());
 System.out.println("3 toString===>"+cl.getResource("webapp/").toString());
 System.out.println("4. getFile===>"+cl.getResource("webapp/").getFile());


 File f = new File(cl.getResource("webapp/").toString());
 Context webContext = tomcat.addWebapp(contextPath, f.toString());  //here i am getting File Not found Exception


     try {

          Desktop.getDesktop().browse(new URL("http://localhost:8081/jsp/Archive.jsp").toURI());

         } catch (Exception e) {

           e.printStackTrace();
          }


    tomcat.start();
    tomcat.getServer().await();


     System.out.println("  tomcat started........");


}

次のようにjar を実行しているとき に、行 でエラーを下回っていますContext webContext = tomcat.addWebapp(contextPath, f.toString());java -jar fatFromEclipse.jarE:/JAR

    E:\JAR>java -jar fatFromEclipse.jar
Picked up _JAVA_OPTIONS: -Xmx512M
path of Main==>/E:/JAR/fatFromEclipse.jar
clasloader==>sun.misc.Launcher$AppClassLoader@19efb05
0===>jar:file:/E:/JAR/fatFromEclipse.jar!/webapp/
1 getPath===>file:/E:/JAR/fatFromEclipse.jar!/webapp/
2 toExternalForm===>jar:file:/E:/JAR/fatFromEclipse.jar!/webapp/
3 toString===>jar:file:/E:/JAR/fatFromEclipse.jar!/webapp/
4. getFile===>file:/E:/JAR/fatFromEclipse.jar!/webapp/

Oct 11, 2018 3:35:36 PM org.apache.catalina.core.StandardContext setPath
WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
Oct 11, 2018 3:35:36 PM org.apache.catalina.startup.Tomcat getWebappConfigFileFromJar
WARNING: Unable to determine web application context.xml jar:file:\E:\JAR\fatFromEclipse.jar!\webapp
java.io.FileNotFoundException: jar:file:\E:\JAR\fatFromEclipse.jar!\webapp (The filename, directory name, or volume label syntax is incorrect)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.jar.JarFile.<init>(JarFile.java:153)
        at java.util.jar.JarFile.<init>(JarFile.java:117)
        at org.apache.catalina.startup.Tomcat.getWebappConfigFileFromJar(Tomcat.java:1137)
        at org.apache.catalina.startup.Tomcat.getWebappConfigFile(Tomcat.java:1117)
        at org.apache.catalina.startup.Tomcat.addWebapp(Tomcat.java:540)
        at org.apache.catalina.startup.Tomcat.addWebapp(Tomcat.java:515)
        at org.apache.catalina.startup.Tomcat.addWebapp(Tomcat.java:197)
        at com.SBMArchievePurge.App.main(App.java:89)



Oct 11, 2018 3:35:38 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8081"]
Oct 11, 2018 3:35:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 11, 2018 3:35:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Oct 11, 2018 3:35:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.28
Oct 11, 2018 3:35:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:188)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        ... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@39d3d3]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4854)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4984)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 6 more
Caused by: java.lang.IllegalArgumentException: The main resource set specified [E:\JAR\tomcat.8081\webapp\jar:file:\E:\JAR\fatFromEclipse.jar!\webapp] is not valid
        at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:723)
        at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:684)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 9 more

Oct 11, 2018 3:35:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:188)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:337)
        at com.SBMArchievePurge.App.main(App.java:151)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 6 more

Exception in thread "main" org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:337)
        at com.SBMArchievePurge.App.main(App.java:151)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 2 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 4 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 6 more

E:\JAR>

問題の解決を手伝ってください。私はたくさん検索しましたが、ほとんどのソリューションは、maven プロジェクトのターゲット フォルダー内で jar を実行していることがわかりました。ここでは、jar を全体として配布して、他のユーザーがそれをダブルクリックするだけで、その内部で Web アプリケーションを実行できるようにします。前もって感謝します !

-マニッシュ

4

0 に答える 0