subchen / jetbrick-template-2x

Template Engine for Java
http://subchen.github.io/jetbrick-template/
Other
388 stars 99 forks source link

通过launch4j把jar生产exe后,不能读取模板资源 #26

Open not3 opened 8 years ago

not3 commented 8 years ago

jetbrick.io.resource.ResourceNotFoundException: /templates/india_cushion.jetx at jetbrick.template.JetEngineImpl.getTemplate(JetEngineImpl.java:101) at controllers.TemplateController.generate_mobile_description(TemplateController.kt:117) at views.MobileDescription$2$1.invoke(MobileDescription.kt:93) at views.MobileDescription$2$1.invoke(MobileDescription.kt:22) at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:18)

使用默认的$loader = jetbrick.template.loader.ClasspathResourceLoader 生产的jar文件可以读取模板文件,使用launch4j后就不能读取了,不知道什么原因

subchen commented 8 years ago

能提供一下 launch4j 的简单用法吗?好方便我进行一下测试。

not3 commented 8 years ago
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
  <dontWrapJar>false</dontWrapJar>
  <headerType>gui</headerType>
  <jar>C:\Users\not3\IdeaProjects\taobao_assistant\target\assistant-0.1.0-jar-with-dependencies.jar</jar>
  <outfile>C:\Users\not3\Downloads\淘宝图片.exe</outfile>
  <errTitle></errTitle>
  <cmdLine></cmdLine>
  <chdir>.</chdir>
  <priority>normal</priority>
  <downloadUrl>http://www.java.com/en/download/manual.jsp</downloadUrl>
  <supportUrl></supportUrl>
  <stayAlive>false</stayAlive>
  <restartOnCrash>false</restartOnCrash>
  <manifest></manifest>
  <icon>C:\Program Files\Java\launch4j\mogu\mogu.ico</icon>
  <classPath>
    <mainClass>Application</mainClass>
  </classPath>
  <jre>
    <path></path>
    <bundledJre64Bit>false</bundledJre64Bit>
    <bundledJreAsFallback>false</bundledJreAsFallback>
    <minVersion>1.8.0</minVersion>
    <maxVersion></maxVersion>
    <jdkPreference>preferJre</jdkPreference>
    <runtimeBits>64</runtimeBits>
  </jre>
</launch4jConfig>```

然后launch4jc myfile.xml

配置很容易懂的,只要加入正确的mvn assembly生产的jar和指定的main类就可以了
也可以通过图形界面生产
subchen commented 8 years ago

建议你可以进行如下的尝试:

  1. 单独使用 mvn assembly 生产的 jar (java -jar assistant-0.1.0-jar-with-dependencies.jar) 运行看看
  2. maven-shade-plugin 打包试试
  3. 修改配置 <dontWrapJar>true</dontWrapJar>

参考:http://stackoverflow.com/questions/6060560/trying-to-integrate-launch4j-in-a-maven-project-using-alakai-plugin

not3 commented 8 years ago

方案1 是可以跑的 方案2 不可以跑,和assembly报一样的错 方案3 是可以的,因为跟方案1的实质是一样的,通过执行jar来跑

通过exe文件的debug日志可以看出jetbrick读取配置文件是正常的,但是读取模板是有问题的

subchen commented 8 years ago

能提供一下用的 jetbrick-templatejetbrick-commons 版本号吗?

如果使用的不是最新版,可以尝试升级到最新版试试。

jetbrick-commons2.1.1 版本里面修复过一个 ClasspathResource 加载失败的问题

not3 commented 8 years ago

用的最新版jetbrick-template 2.1.2 试着把jetbrick-commons也更新到2.1.2也不行

subchen commented 8 years ago

我用下面的 pom.xml 打包 launch4j,没有成功,好像是 launch4j 不支持 64bit? http://stackoverflow.com/questions/8142162/launch4j-maven-plugin-will-not-work-on-64-bit-linux-machine

Linux & Mac 都没有成功。不知道你有什么办法?

Linux

[ERROR]
net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: java.io.IOException: Cannot run program "/root/.m2/repository/org/bluestemsoftware/open/maven/plugin/launch4j-plugin/1.5.0.0/launch4j-plugin-1.5.0.0-workdir-linux/bin/windres": error=2, No such file or directory
    at net.sf.launch4j.Builder.build(Builder.java:145)
    at com.akathist.maven.plugins.launch4j.Launch4jMojo.execute(Launch4jMojo.java:326)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)

Mac

[ERROR]
net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: java.io.IOException: Cannot run program "/Users/xxxxx/.m2/repository/org/bluestemsoftware/open/maven/plugin/launch4j-plugin/1.5.0.0/launch4j-plugin-1.5.0.0-workdir-mac/bin/windres": error=86, Bad CPU type in executable
    at net.sf.launch4j.Builder.build(Builder.java:145)
    at com.akathist.maven.plugins.launch4j.Launch4jMojo.execute(Launch4jMojo.java:326)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>shaded</shadedClassifierName>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
                <artifactId>launch4j-plugin</artifactId>
                <version>1.5.0.0</version>
                <executions>
                    <execution>
                        <id>l4j-cli</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <outfile>target/app-cli.exe</outfile>
                            <jar>target/jetx-2x-samples-app-1.0-SNAPSHOT-shaded.jar</jar>
                            <errTitle>App Err</errTitle>
                            <classPath>
                                <mainClass>jetbrick.template.samples.App</mainClass>
                            </classPath>
                            <jre>
                                <minVersion>1.6.0</minVersion>
                                <maxVersion>1.8.0</maxVersion>
                                <initialHeapSize>128</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
not3 commented 8 years ago

我用命名行的,没有用maven里设置launch4j,感觉没必要 On Linux use the launch4j script.

launch4j ./demo/l4j/config.xml

我手头没有liunx和mac的环境