把配置文件放在jar包外|如何用maven将配置文件打在jar包外

1. 如何用maven将配置文件打在jar包外

您好,很高兴能帮助您,pom如下,最后mvn package -Dmaven.test.skip=true结果在target下面有jar,lib是依赖库,配置文件放在和jar一个目录<build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <versionRange>[2.0,)</versionRange> <goals> <goal>-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!– 打包源码一起发布到maven仓库中 –> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin –> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>***Main Application *** </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></id> <phase>package</phase> <goals> <goal>-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin end –> <!– 生成可执行JAR包命令 maven-shade-plugin <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>***.Application ***</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> –> </plugins> </build>

2. 如何用maven将配置文件打在jar包外

<build><sourceDirectory>src/main/java</sourceDirectory><resources><resource><directory>src/main/resources</directory><targetPath>${project.build.directory}</targetPath><excludes><exclude>**/*.java</exclude></excludes></resource></resources><testSourceDirectory>src/test/java</testSourceDirectory><testResources><testResource><directory>src/test/resources</directory><filtering>true</filtering><excludes><exclude>**/*.java</exclude></excludes></testResource></testResources><pluginManagement><plugins><plugin><groupId>org.eclipse.m2e</groupId><artifactId>lifecycle-mapping</artifactId><version>1.0.0</version><configuration><lifecycleMappingMetadata><pluginExecutions><pluginExecution><pluginExecutionFilter><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><versionRange>[2.0,)</versionRange><goals><goal>-dependencies</goal></goals></pluginExecutionFilter><action><ignore/></action></pluginExecution></pluginExecutions></lifecycleMappingMetadata></configuration></plugin></plugins></pluginManagement><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.6</source><target>1.6</target><encoding>UTF-8</encoding></configuration></plugin><!–打包源码一起发布到maven仓库中–><plugin><artifactId>maven-source-plugin</artifactId><version>2.1</version><configuration><attach>true</attach></configuration><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin><!–生成可执行JAR包命令maven-jar-plugin–><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib/</classpathPrefix><mainClass>***MainApplication***</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></id><phase>package</phase><goals><goal>-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin><!–生成可执行JAR包命令maven-jar-pluginend–><!–生成可执行JAR包命令maven-shade-plugin<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>1.2.1</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><transformers><transformerimplementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"><mainClass>***.Application***</mainClass></transformer></transformers></configuration></execution></executions></plugin>–></plugins></build>

3. 如何用maven将配置文件打在jar包外

pom如下,最后mvn package -Dmaven.test.skip=true结果在target下面有jar,lib是依赖库,配置文件放在和jar一个目录<build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <versionRange>[2.0,)</versionRange> <goals> <goal>-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!– 打包源码一起发布到maven仓库中 –> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin –> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>***Main Application *** </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></id> <phase>package</phase> <goals> <goal>-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin end –> <!– 生成可执行JAR包命令 maven-shade-plugin <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>***.Application ***</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> –> </plugins> </build>

4. 如何用maven将配置文件打在jar包外

问题已解决,pom如下,最后mvn package -Dmaven.test.skip=true结果在target下面有jar,lib是依赖库,配置文件放在和jar一个目录<span></span><build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <versionRange>[2.0,)</versionRange> <goals> <goal>-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!– 打包源码一起发布到maven仓库中 –> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin –> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>***Main Application *** </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></id> <phase>package</phase> <goals> <goal>-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin end –> <!– 生成可执行JAR包命令 maven-shade-plugin <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>***.Application ***</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> –> </plugins> </build>

5. 如何用maven将配置文件打在jar包外

pom如下,最后mvn package -Dmaven.test.skip=true结果在target下面有jar,lib是依赖库,配置文件放在和jar一个目录 <build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>

6. 如何用maven将配置文件打在jar包外

您好,很高兴能帮助您, pom如下,最后mvn package -Dmaven.test.skip=true结果在target下面有jar,lib是依赖库,配置文件放在和jar一个目录 <build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>

7. 如何用maven将配置文件打在jar包外

一、导出到默认目录 targed/dependency 从Maven项目中导出项目依赖的jar包:进入工程pom.xml 所在的目录下,执行如下命令: 1、mvn dependency:-dependencies或在eclipse中,选择项目的pom.xml文件,点击右键菜单中的Run As,见下图红框中

8. 如何用maven将配置文件打在jar包外

您好,很高兴能帮助您,pom如下,最后mvn package -Dmaven.test.skip=true结果在target下面有jar,lib是依赖库,配置文件放在和jar一个目录<build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <versionRange>[2.0,)</versionRange> <goals> <goal>-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!– 打包源码一起发布到maven仓库中 –> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin –> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>***Main Application *** </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></id> <phase>package</phase> <goals> <goal>-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <!– 生成可执行JAR包命令 maven-jar-plugin end –> <!– 生成可执行JAR包命令 maven-shade-plugin <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>***.Application ***</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> –> </plugins> </build>你的采纳是我前进的动力,还有不懂的地方,请你继续“追问”!如你还有别的问题,可另外向我求助;答题不易,互相理解,互相帮助!

9. 如何用maven将配置文件打在jar包外

手动直接修改:1,打开maven安装文件夹,打到其下的conf文件夹,找到settings.xml文件2,在内settings.xml文件中settings根目录下添加上容d:/m2d:/m2为你想设置的本地磁盘位置如注意修改后,如果使用的是eclipse开发工具,要在eclipse中指定:window->preferences下,找到maven(前提是eclipse已集成maven)

10. 如何用maven将配置文件打在jar包外

<build><sourceDirectory>src/main/java</sourceDirectory><resources><resource><directory>src/main/resources</directory><targetPath>${project.build.directory}</targetPath><excludes><exclude>**/*.java</exclude></excludes></resource></resources><testSourceDirectory>src/test/java</testSourceDirectory><testResources><testResource><directory>src/test/resources</directory><filtering>true</filtering><excludes><exclude>**/*.java</exclude></excludes></testResource></testResources><pluginManagement><plugins><plugin><groupId>org.eclipse.m2e</groupId><artifactId>lifecycle-mapping</artifactId><version>1.0.0</version><configuration><lifecycleMappingMetadata><pluginExecutions><pluginExecution><pluginExecutionFilter><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><versionRange>[2.0,)</versionRange><goals><goal>-dependencies</goal></goals></pluginExecutionFilter><action><ignore/></action></pluginExecution></pluginExecutions></lifecycleMappingMetadata></configuration></plugin></plugins></pluginManagement><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.6</source><target>1.6</target><encoding>UTF-8</encoding></configuration></plugin><!–打包源码一起发布到maven仓库中–><plugin><artifactId>maven-source-plugin</artifactId><version>2.1</version><configuration><attach>true</attach></configuration><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin><!–生成可执行JAR包命令maven-jar-plugin–><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib/</classpathPrefix><mainClass>***MainApplication***</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></id><phase>package</phase><goals><goal>-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin><!–生成可执行JAR包命令maven-jar-pluginend–><!–生成可执行JAR包命令maven-shade-plugin<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>1.2.1</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><transformers><transformerimplementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"><mainClass>***.Application***</mainClass></transformer></transformers></configuration></execution></executions></plugin>–></plugins></build>

可以参考这个配置,使用maven package将在target下面生成jar包,lib是依赖库,配置文件放在和jar一个目录


赞 (0)