maven写入配置文件|如何用maven将配置文件打在jar包外

A. 如何用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>

B. 如何用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>你的采纳是我前进的动力,还有不懂的地方,请你继续“追问”!如你还有别的问题,可另外向我求助;答题不易,互相理解,互相帮助!

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

知道一点点,给个类似的例子:<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>-something</id><phase>prepare-package</phase><goals><goal>-dependencies</goal></goals><configuration><excludeGroupIds> 要排除的groupids </excludeGroupIds><excludeArtifactIds>要排除的artifactIds</excludeArtifactIds><includeTypes>jar</includeTypes><outputDirectory>指定输出的路径</outputDirectory></configuration></execution></executions></plugin></plugins> </build>具体再去看看 dependency-plugin 的用法。

D. 如何用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>

E. 如何用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>

F. 如何用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一个目录

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

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

H. 如何用eclipse写maven

下载解压Maven包增加两个环境变量Path : 解压目录/binM2_HOME: 解压目录验证安装:开始->运行->cmd进入命令行窗口 Mvn -vEclipse中的Maven设置:Window->preferences->maven->installation->add Maven的安装目录Maven的配置文件全局配置文件的位置: ${maven.home}/conf/settings.xml 需拷贝到用户模式下用户配置文件的位置:${user.home}/.m2/settings.xmlMaven库的设置:Maven引用的jar包,都会通过网络下载添加到maven的库中,方便下次调用,默认存放的库是${user.home}/.m2/repository ,库中的数据越会来月多,存放在C盘,随着系统盘的格式化库会丢失,所以需要自定义库的位置。下载一份包含较多jar包的maven库文件(M2repository.zip),解压并修改用户(user)配置文件<localRepository>库文件的目录</localRepository>也可以在Window->preferences->maven->user settings ->Local Repository中修改使用Eclipse创建Maven项目:File->new->other..àMaven->Maven project创建jar项目,可以选择使用maven-archetype-quickstart来创建创建war项目,可以选择使用cocoon-archetype-webapp来创建接着填写项目的坐标信息,maven使得项目更有层次性,利于管理groupId:项目或者组织的唯一标志,并且配置时生成的路径也是由此生成,如org.codehaus.mojo生成的相对路径为:/org/codehaus/mojoartifactId: 项目的通用名称version:项目的版本packaging: 打包的机制,如pom, jar, maven-plugin, ejb, war, ear, rar, pa Pom.xml包含了项目的所有信息(以下不是必要信息)项目的依赖:<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency>安装Jetty插件:<plugin><groupId>org.mortbay.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>7.1.6.v20100715</version><configuration><scanIntervalSeconds>10</scanIntervalSeconds><webAppConfig><contextPath>/projectX</contextPath></webAppConfig></configuration></plugin>运行Maven项目:运行Jar项目右键->run as -> java application运行war项目,需要使用到Tomcat或者在pom.xml里面添加jetty的插件,在命令行窗口,转到项目目录 输入mvn jetty:run

I. eclipse里安配置maven,需要修改的配置文件为

咨询记录 · 回答于2021-10-20


赞 (0)