NutzCN Logo
精华 如何将依赖jar包打在外面
发布于 2525天前 作者 文涛(wentao) 3259 次浏览 复制 上一个帖子 下一个帖子
标签: nutzboot

每次打包出来的jar都好大,所以想把依赖包打在主jar包外面的lib目录,修改了pom.xml配置文件,依赖包确实在外面了,但主包的大小依然没变,请问有办法吗
配置如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <!--<addDefaultImplementationEntries>true</addDefaultImplementationEntries>-->
                <mainClass>tool.wentao.MainLauncher</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>
<!-- 拷贝依赖的jar包到lib目录 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>
                    ${project.build.directory}/lib
                </outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>
35 回复

是不是还加了其他plugin?

完整的build是这样的

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*</exclude>
                </excludes>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <outputDirectory>
                                ${project.build.directory}
                            </outputDirectory>   <!-- 表示把配置文件拷到和jar包同一个路径下 -->
                            <resources>
                                <resource>
                                    <directory>src/main/resources/</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                    <useIncrementalCompilation>false</useIncrementalCompilation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <additionalparam>-Xdoclint:none</additionalparam>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <!--<addDefaultImplementationEntries>true</addDefaultImplementationEntries>-->
                            <mainClass>tool.wentao.MainLauncher</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <!-- 拷贝依赖的jar包到lib目录 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/nutz/org.nutz.boot.starter.NbStarter</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>tool.wentao.MainLauncher</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

shade的缘故,删掉

整个shade-plugin删掉后编译运行报错

Exception in thread "main" java.lang.NoClassDefFoundError: org/nutz/boot/NbApp
        at tool.wentao.MainLauncher.main(MainLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.nutz.boot.NbApp
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

manifest没设置对吧

我看了下jar包内的MANIFEST.MF文件内容没错啊,为什么就是找不到NbApp呢

Manifest-Version: 1.0
Implementation-Title: demo
Implementation-Version: 1.0-SNAPSHOT
Built-By: swt
Specification-Title: demo
Implementation-Vendor-Id: io.nutz
Class-Path: lib/nutzboot-starter-swagger-2.2-20180121.023649-37.jar li
 b/swagger-servlet-1.5.17.jar lib/swagger-core-1.5.17.jar lib/commons-
 lang3-3.2.1.jar lib/jackson-annotations-2.8.9.jar lib/jackson-databin
 d-2.8.9.jar lib/jackson-core-2.8.9.jar lib/jackson-dataformat-yaml-2.
 8.9.jar lib/snakeyaml-1.17.jar lib/swagger-models-1.5.17.jar lib/swag
 ger-annotations-1.5.17.jar lib/validation-api-1.1.0.Final.jar lib/ref
 lections-0.9.11.jar lib/javassist-3.21.0-GA.jar lib/guava-20.0.jar li
 b/nutzboot-core-2.2-20180121.023356-40.jar lib/javax.servlet-api-3.1.
 0.jar lib/nutzboot-starter-jetty-2.2-20180121.023509-40.jar lib/jetty
 -servlets-9.4.8.v20171121.jar lib/jetty-continuation-9.4.8.v20171121.
 jar lib/jetty-http-9.4.8.v20171121.jar lib/jetty-util-9.4.8.v20171121
 .jar lib/jetty-io-9.4.8.v20171121.jar lib/jetty-webapp-9.4.8.v2017112
 1.jar lib/jetty-xml-9.4.8.v20171121.jar lib/jetty-servlet-9.4.8.v2017
 1121.jar lib/jetty-security-9.4.8.v20171121.jar lib/jetty-server-9.4.
 8.v20171121.jar lib/websocket-server-9.4.8.v20171121.jar lib/websocke
 t-common-9.4.8.v20171121.jar lib/websocket-api-9.4.8.v20171121.jar li
 b/websocket-client-9.4.8.v20171121.jar lib/jetty-client-9.4.8.v201711
 21.jar lib/websocket-servlet-9.4.8.v20171121.jar lib/javax-websocket-
 server-impl-9.4.8.v20171121.jar lib/jetty-annotations-9.4.8.v20171121
 .jar lib/jetty-plus-9.4.8.v20171121.jar lib/javax.annotation-api-1.2.
 jar lib/asm-6.0.jar lib/asm-commons-6.0.jar lib/asm-tree-6.0.jar lib/
 javax-websocket-client-impl-9.4.8.v20171121.jar lib/javax.websocket-c
 lient-api-1.0.jar lib/javax.websocket-api-1.0.jar lib/jul-to-slf4j-1.
 7.25.jar lib/nutz-plugins-websocket-1.r.65-20180119.163235-46.jar lib
 /nutzboot-starter-nutz-mvc-2.2-20180121.024514-34.jar lib/nutzboot-st
 arter-nutz-dao-2.2-20180121.023624-39.jar lib/nutz-plugins-daocache-1
 .r.65-20180119.162205-45.jar lib/nutzboot-starter-jdbc-2.2-20180121.0
 23834-36.jar lib/druid-1.1.5.jar lib/nutzboot-starter-redis-2.2-20180
 121.023950-35.jar lib/nutz-integration-jedis-1.r.65-20180119.161636-4
 5.jar lib/jedis-2.9.0.jar lib/commons-pool2-2.4.2.jar lib/nutzboot-st
 arter-quartz-2.2-20180121.023925-36.jar lib/nutz-integration-quartz-1
 .r.65-20180119.161843-45.jar lib/nutz-1.r.65-20180123.140337-73.jar l
 ib/quartz-2.3.0.jar lib/mchange-commons-java-0.2.11.jar lib/nutzboot-
 starter-beetl-2.2-20180121.024106-35.jar lib/beetl-2.7.26.jar lib/ant
 lr4-runtime-4.2.jar lib/org.abego.treelayout.core-1.0.1.jar lib/antlr
 4-annotations-4.2.jar lib/slf4j-log4j12-1.7.25.jar lib/slf4j-api-1.7.
 25.jar lib/log4j-1.2.17.jar lib/h2-1.4.196.jar lib/hutool-all-4.0.0.j
 ar lib/poi-ooxml-3.17.jar lib/poi-3.17.jar lib/commons-codec-1.10.jar
  lib/commons-collections4-4.1.jar lib/poi-ooxml-schemas-3.17.jar lib/
 xmlbeans-2.6.0.jar lib/stax-api-1.0.1.jar lib/curvesapi-1.04.jar .
Created-By: Apache Maven 3.5.2
Build-Jdk: 1.8.0_152
Specification-Version: 1.0
Main-Class: tool.wentao.MainLauncher

里面没有nutzboot-starter-core.jar

那就很尴尬了,我试着加入依赖

<dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-core</artifactId>
        </dependency>

可是编译报错

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-resources-plugin is missing. @ line 119, column 12
[ERROR] 'dependencies.dependency.version' for org.nutz:nutzboot-starter-core:jar is missing. @ line 56, column 21
 @ 
[ERROR] The build could not read 1 project -> [Help 1]

加上版本号

我发现org/nutz/boot/NbApp是在nutzboot-core所以我加了nutzboot-core依赖,编译不报错,但依然报错 ,找不到类

[ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project io.nutz:demo:jar:2.2-SNAPSHOT: Failure to find org.nutz:nutzboot-starter-core:jar:2.2-SNAPSHOT in http://jfrog.nutz.cn/artifactory/libs-release was cached in the local repository, resolution will not be reattempted until the update interval of nutz has elapsed or updates are forced -> [Help 1]

这个玩意都搞了我一天了,也是醉了,强伯症无解

加了

        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-core</artifactId>
            <version>2.1.0</version>
        </dependency>

现在提示

Caused by: java.lang.ClassNotFoundException: org.nutz.ioc.IocLoader
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 1 more

看来还有不少依赖项要加,但是单独打包缺一个都不少

删掉这些东西

          <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>

整个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"
4.0.0
io.nutz
demo
2.2-SNAPSHOT
jar

<nutzboot.version>2.2-SNAPSHOT</nutzboot.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>




org.nutz
nutzboot-parent
${nutzboot.version}
pom
import





org.nutz
nutzboot-starter-swagger


org.nutz
nutzboot-starter-jetty


org.nutz
nutzboot-starter-nutz-mvc


org.nutz
nutzboot-starter-nutz-dao


org.nutz
nutzboot-starter-jdbc


org.nutz
nutzboot-core
2.1.0

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
    </dependency>
    <dependency>
        <groupId>org.nutz</groupId>
        <artifactId>nutzboot-starter-redis</artifactId>
    </dependency>
    <dependency>
        <groupId>org.nutz</groupId>
        <artifactId>nutzboot-starter-quartz</artifactId>
    </dependency>
    <dependency>
        <groupId>org.nutz</groupId>
        <artifactId>nutzboot-starter-beetl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.196</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <!--引用Hutool-->
    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>4.0.0</version>
    </dependency>
    <!--引用poi 用于处理excel-->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>nutz</id>
        <url>http://jfrog.nutz.cn/artifactory/libs-release</url>
    </repository>
    <repository>
        <id>nutz-snapshots</id>
        <url>http://jfrog.nutz.cn/artifactory/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/*</exclude>
            </excludes>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <outputDirectory>
                            ${project.build.directory}
                        </outputDirectory>   <!-- 表示把配置文件拷到和jar包同一个路径下 -->
                        <resources>
                            <resource>
                                <directory>src/main/resources/</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
                <useIncrementalCompilation>false</useIncrementalCompilation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.3</version>
            <configuration>
                <additionalparam>-Xdoclint:none</additionalparam>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        <mainClass>tool.wentao.MainLauncher</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <!-- 拷贝依赖的jar包到lib目录 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/lib
                        </outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-shade-plugin</artifactId>-->
            <!--<version>3.0.0</version>-->
            <!--<executions>-->
                <!--<execution>-->
                    <!--<phase>package</phase>-->
                    <!--<goals>-->
                        <!--<goal>shade</goal>-->
                    <!--</goals>-->
                    <!--<configuration>-->
                        <!--<transformers>-->
                            <!--<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />-->
                            <!--<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">-->
                                <!--<resource>META-INF/nutz/org.nutz.boot.starter.NbStarter</resource>-->
                            <!--</transformer>-->
                            <!--<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
                                <!--<mainClass>tool.wentao.MainLauncher</mainClass>-->
                            <!--</transformer>-->
                        <!--</transformers>-->
                    <!--</configuration>-->
                <!--</execution>-->
            <!--</executions>-->
        <!--</plugin>-->
    </plugins>
</build>

<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>io.nutz</groupId>
    <artifactId>demo</artifactId>
    <version>2.2-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <nutzboot.version>2.2-SNAPSHOT</nutzboot.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.nutz</groupId>
                <artifactId>nutzboot-parent</artifactId>
                <version>${nutzboot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-swagger</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-nutz-mvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-nutz-dao</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-core</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-quartz</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-beetl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.196</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!--引用Hutool-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.0.0</version>
        </dependency>
        <!--引用poi 用于处理excel-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>nutz</id>
            <url>http://jfrog.nutz.cn/artifactory/libs-release</url>
        </repository>
        <repository>
            <id>nutz-snapshots</id>
            <url>http://jfrog.nutz.cn/artifactory/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*</exclude>
                </excludes>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <outputDirectory>
                                ${project.build.directory}
                            </outputDirectory>   <!-- 表示把配置文件拷到和jar包同一个路径下 -->
                            <resources>
                                <resource>
                                    <directory>src/main/resources/</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                    <useIncrementalCompilation>false</useIncrementalCompilation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <additionalparam>-Xdoclint:none</additionalparam>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            <mainClass>tool.wentao.MainLauncher</mainClass>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <!-- 拷贝依赖的jar包到lib目录 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--<plugin>-->
                <!--<groupId>org.apache.maven.plugins</groupId>-->
                <!--<artifactId>maven-shade-plugin</artifactId>-->
                <!--<version>3.0.0</version>-->
                <!--<executions>-->
                    <!--<execution>-->
                        <!--<phase>package</phase>-->
                        <!--<goals>-->
                            <!--<goal>shade</goal>-->
                        <!--</goals>-->
                        <!--<configuration>-->
                            <!--<transformers>-->
                                <!--<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />-->
                                <!--<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">-->
                                    <!--<resource>META-INF/nutz/org.nutz.boot.starter.NbStarter</resource>-->
                                <!--</transformer>-->
                                <!--<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
                                    <!--<mainClass>tool.wentao.MainLauncher</mainClass>-->
                                <!--</transformer>-->
                            <!--</transformers>-->
                        <!--</configuration>-->
                    <!--</execution>-->
                <!--</executions>-->
            <!--</plugin>-->
        </plugins>
    </build>
</project>

overWriteSnapshots 你就没改

我是去掉了的,后来又还原回来的。。。。。。

我现在已经删掉了,编译后还是报错

Exception in thread "main" java.lang.NoClassDefFoundError: org/nutz/ioc/IocLoader
        at tool.iptv.MainLauncher.main(MainLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.nutz.ioc.IocLoader
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

关键还是看lib目录有没有需要的jar

这是lib目录的所有文件

antlr4-annotations-4.2.jar
antlr4-runtime-4.2.jar
asm-6.0.jar
asm-commons-6.0.jar
asm-tree-6.0.jar
beetl-2.7.26.jar
commons-codec-1.10.jar
commons-collections4-4.1.jar
commons-lang3-3.2.1.jar
commons-pool2-2.4.2.jar
curvesapi-1.04.jar
druid-1.1.5.jar
guava-20.0.jar
h2-1.4.196.jar
hamcrest-core-1.3.jar
hutool-all-4.0.0.jar
jackson-annotations-2.8.9.jar
jackson-core-2.8.9.jar
jackson-databind-2.8.9.jar
jackson-dataformat-yaml-2.8.9.jar
javassist-3.21.0-GA.jar
javax-websocket-client-impl-9.4.8.v20171121.jar
javax-websocket-server-impl-9.4.8.v20171121.jar
javax.annotation-api-1.2.jar
javax.servlet-api-3.1.0.jar
javax.websocket-api-1.0.jar
javax.websocket-client-api-1.0.jar
jedis-2.9.0.jar
jetty-annotations-9.4.8.v20171121.jar
jetty-client-9.4.8.v20171121.jar
jetty-continuation-9.4.8.v20171121.jar
jetty-http-9.4.8.v20171121.jar
jetty-io-9.4.8.v20171121.jar
jetty-plus-9.4.8.v20171121.jar
jetty-security-9.4.8.v20171121.jar
jetty-server-9.4.8.v20171121.jar
jetty-servlet-9.4.8.v20171121.jar
jetty-servlets-9.4.8.v20171121.jar
jetty-util-9.4.8.v20171121.jar
jetty-webapp-9.4.8.v20171121.jar
jetty-xml-9.4.8.v20171121.jar
jul-to-slf4j-1.7.25.jar
junit-4.12.jar
log4j-1.2.17.jar
mchange-commons-java-0.2.11.jar
nutz-1.r.65-SNAPSHOT.jar
nutz-integration-jedis-1.r.65-SNAPSHOT.jar
nutz-integration-quartz-1.r.65-SNAPSHOT.jar
nutz-plugins-daocache-1.r.65-SNAPSHOT.jar
nutz-plugins-websocket-1.r.65-SNAPSHOT.jar
nutzboot-core-2.1.0.jar
nutzboot-starter-beetl-2.2-SNAPSHOT.jar
nutzboot-starter-jdbc-2.2-SNAPSHOT.jar
nutzboot-starter-jetty-2.2-SNAPSHOT.jar
nutzboot-starter-nutz-dao-2.2-SNAPSHOT.jar
nutzboot-starter-nutz-mvc-2.2-SNAPSHOT.jar
nutzboot-starter-quartz-2.2-SNAPSHOT.jar
nutzboot-starter-redis-2.2-SNAPSHOT.jar
nutzboot-starter-swagger-2.2-SNAPSHOT.jar
org.abego.treelayout.core-1.0.1.jar
poi-3.17.jar
poi-ooxml-3.17.jar
poi-ooxml-schemas-3.17.jar
quartz-2.3.0.jar
reflections-0.9.11.jar
slf4j-api-1.7.25.jar
slf4j-log4j12-1.7.25.jar
snakeyaml-1.17.jar
stax-api-1.0.1.jar
swagger-annotations-1.5.17.jar
swagger-core-1.5.17.jar
swagger-models-1.5.17.jar
swagger-servlet-1.5.17.jar
validation-api-1.1.0.Final.jar
websocket-api-9.4.8.v20171121.jar
websocket-client-9.4.8.v20171121.jar
websocket-common-9.4.8.v20171121.jar
websocket-server-9.4.8.v20171121.jar
websocket-servlet-9.4.8.v20171121.jar
xmlbeans-2.6.0.jar

我测试了一下, 输出是这样, 看上去就不对:

Manifest-Version: 1.0
Implementation-Title: nutzboot-demo-simple-dao
Implementation-Version: 2.2-SNAPSHOT
Built-By: Administrator
Implementation-Vendor-Id: org.nutz
Class-Path: lib/nutzboot-starter-nutz-mvc-2.2-20180124.024116-36.jar l
 ib/nutzboot-starter-nutz-dao-2.2-20180124.121851-42.jar lib/nutz-plug
 ins-daocache-1.r.65-20180119.162205-45.jar lib/nutzboot-starter-jdbc-
 2.2-20180124.122259-39.jar lib/druid-1.1.5.jar lib/nutzboot-starter-j
 etty-2.2-20180124.121710-43.jar lib/jetty-servlets-9.4.8.v20171121.ja
 r lib/jetty-continuation-9.4.8.v20171121.jar lib/jetty-http-9.4.8.v20
 171121.jar lib/jetty-util-9.4.8.v20171121.jar lib/jetty-io-9.4.8.v201
 71121.jar lib/jetty-webapp-9.4.8.v20171121.jar lib/jetty-xml-9.4.8.v2
 0171121.jar lib/jetty-servlet-9.4.8.v20171121.jar lib/jetty-security-
 9.4.8.v20171121.jar lib/jetty-server-9.4.8.v20171121.jar lib/websocke
 t-server-9.4.8.v20171121.jar lib/websocket-common-9.4.8.v20171121.jar
  lib/websocket-api-9.4.8.v20171121.jar lib/websocket-client-9.4.8.v20
 171121.jar lib/jetty-client-9.4.8.v20171121.jar lib/websocket-servlet
 -9.4.8.v20171121.jar lib/javax-websocket-server-impl-9.4.8.v20171121.
 jar lib/jetty-annotations-9.4.8.v20171121.jar lib/jetty-plus-9.4.8.v2
 0171121.jar lib/javax.annotation-api-1.2.jar lib/asm-6.0.jar lib/asm-
 commons-6.0.jar lib/asm-tree-6.0.jar lib/javax-websocket-client-impl-
 9.4.8.v20171121.jar lib/javax.websocket-client-api-1.0.jar lib/javax.
 websocket-api-1.0.jar lib/jul-to-slf4j-1.7.25.jar lib/nutz-plugins-we
 bsocket-1.r.65-20180119.163235-46.jar lib/nutzboot-starter-swagger-2.
 2-20180124.121932-40.jar lib/swagger-servlet-1.5.17.jar lib/swagger-c
 ore-1.5.17.jar lib/commons-lang3-3.2.1.jar lib/jackson-annotations-2.
 8.9.jar lib/jackson-databind-2.8.9.jar lib/jackson-core-2.8.9.jar lib
 /jackson-dataformat-yaml-2.8.9.jar lib/snakeyaml-1.17.jar lib/swagger
 -models-1.5.17.jar lib/swagger-annotations-1.5.17.jar lib/validation-
 api-1.1.0.Final.jar lib/reflections-0.9.11.jar lib/javassist-3.21.0-G
 A.jar lib/guava-20.0.jar lib/slf4j-log4j12-1.7.25.jar lib/slf4j-api-1
 .7.25.jar lib/log4j-1.2.17.jar lib/h2-1.4.196.jar lib/nutzboot-core-2
 .2-20180124.121519-43.jar lib/nutz-1.r.65-20180124.051755-76.jar lib/
 javax.servlet-api-3.1.0.jar
Created-By: Apache Maven 3.5.2
Build-Jdk: 1.8.0_151
Implementation-URL: http://nutzam.com/nutzboot-demo/nutzboot-demo-simp
 le/nutzboot-demo-simple-dao
Main-Class: io.nutz.demo.simple.MainLauncher

我试了一下, 没成功, 但我找到另外一种启动方式:

java -cp lib/* -jar nutzboot-demo-simple-2.2-SNAPSHOT.jar

我发现这样也能启动

java -cp nutzboot-demo-simple-dao-2.2-SNAPSHOT.jar io.nutz.demo.simple.MainLauncher

看来是 java -jar XXX.jar 是不会读取Manifest里面的class path定义的

不对... 刚刚又试了了一下, 是可以的直接 java -jar XXX.jar的

整份pom.xml是这样的(也许是useUniqueVersions的问题?):

<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>
	<parent>
		<groupId>org.nutz</groupId>
		<artifactId>nutzboot-demo-simple</artifactId>
		<version>2.2-SNAPSHOT</version>
	</parent>
	<artifactId>nutzboot-demo-simple-dao</artifactId>
	<properties>
		<docker.image.prefix>nutzboot</docker.image.prefix>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutzboot-starter-nutz-mvc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutzboot-starter-nutz-dao</artifactId>
		</dependency>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutzboot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutzboot-starter-jetty</artifactId>
		</dependency>
		<dependency>
			<groupId>org.nutz</groupId>
			<artifactId>nutzboot-starter-swagger</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</dependency>
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<version>1.4.196</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<useUniqueVersions>false</useUniqueVersions>
							<!--<addDefaultImplementationEntries>true</addDefaultImplementationEntries> -->
							<mainClass>io.nutz.demo.simple.MainLauncher</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
			<!-- 拷贝依赖的jar包到lib目录 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.directory}/lib</outputDirectory>
							<overWriteReleases>false</overWriteReleases>
							<overWriteSnapshots>false</overWriteSnapshots>
							<overWriteIfNewer>true</overWriteIfNewer>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

打包命令是:

mvn clean package -U

现在不报类找不到了,但又报出一个新的错误

[INFO ] 09:31:35.273 org.nutz.resource.impl.ErrorResourceLocation.<init>(ErrorResourceLocation.java:28) - [loc=/Users/swt/Documents/%e5%8a%9e%e5%85%ac/git/tool.wentao/target]not exist
[DEBUG] 09:31:35.280 org.nutz.resource.Scans.printLocations(Scans.java:527) - Locations count=3 time use 16ms
[DEBUG] 09:31:35.283 org.nutz.resource.Scans.scan(Scans.java:280) - Found 0 resource by src( custom/ ) , regex( ^.+[.]properties$ )
[DEBUG] 09:31:35.337 org.nutz.castor.Castors.reload(Castors.java:115) - Using 95 castor for Castors
[ERROR] 09:31:35.338 org.nutz.boot.NbApp.run(NbApp.java:173) - something happen
java.lang.RuntimeException: folder or file like '^.+[.]properties$' no found in custom/
        at org.nutz.lang.Lang.makeThrow(Lang.java:152)
        at org.nutz.resource.Scans.loadResource(Scans.java:112)
        at org.nutz.ioc.impl.PropertiesProxy.getResources(PropertiesProxy.java:154)
        at org.nutz.ioc.impl.PropertiesProxy.setPaths(PropertiesProxy.java:110)
        at org.nutz.boot.config.impl.PropertiesConfigureLoader.init(PropertiesConfigureLoader.java:21)
        at org.nutz.boot.NbApp.prepareConfigureLoader(NbApp.java:289)
        at org.nutz.boot.NbApp.prepare(NbApp.java:229)
        at org.nutz.boot.NbApp._run(NbApp.java:184)
        at org.nutz.boot.NbApp.run(NbApp.java:170)
        at tool.wentao.MainLauncher.main(MainLauncher.java:62)

不要放在中文路径下...

好吧,确实可以了,感谢

添加回复
请先登陆
回到顶部