maven编译xml
1. 创建一个maven项目pom.xml头部报错,求解决
1.新建一个maven空工程, 2.把代码拷到maven空工程相应src文件夹内,当然,配置文件放resource文件夹里,jar包神马的都不要, 3,修改pom,把项目所需jar包都写到pom的<dependency>里. (没有<parent>的情况下,如果有parent,代码和pom都要随之调整,小复杂,看看maven文档再改~) 4.把这个整理好的工程,import到eclipse中。 5.mvn package命令行编译,或eclipse自带maven编译打包都行,反正已经能用了~
2. maven编译时出错了
在对应的类里找 repaint()这个方法是在什么包里.
缺少包啊,需要在pom.xml里添加相应包的<dependency>引用起来就好了.
3. 怎么编译运行从github上下载下来的maven项目源码(我想调试运行的是sonarqube的源码)跪求大神orz
maven 编译命令
从别处拷贝来的maven项目,有时候会出现不能debug关联的情况,即按住ctrl键后不能跳转到相应的类或方法,这是需要eclipse环境生成 Eclipse 项目文件的。
可以在cmd命令窗口下进入到maven项目包含pom.xml文件的目录下,运行 mvn eclipse:eclipse 命令即可,如果还不行,可使用mvn compile :编译源代码 命令。
--------------------------------------------------------------------------------------------------------------------------------
下面是一些maven的常用命令:
Maven2 的运行命令为 : mvn ,
常用命令为 :
mvn archetype:create :创建 Maven 项目
mvn compile :编译源代码
mvn test-compile :编译测试代码
mvn test : 运行应用程序中的单元测试
mvn site : 生成项目相关信息的网站
mvn clean :清除目标目录中的生成结果
mvn package : 依据项目生成 jar 文件
mvn install :在本地 Repository 中安装 jar
mvn eclipse:eclipse :生成 Eclipse 项目文件
生成项目
建一个 java 项目 : mvn archetype:create -DgroupId=com.demo -DartifactId=App
建一个 web 项目 : mvn archetype:create -DgroupId=com.demo -DartifactId=web-app -DarchetypeArtifactId=maven-archetype-webapp
生成 Eclipse 项目
普通 Eclipse 项目执行 : mvn eclipse:eclipse
Eclipse WTP 项目执行 : mvn eclipse:eclipse –Dwtpversion=1.0
更详细的,自己网络搜索 maven 编译,学习一下吧
4. maven为什么会有时候不编译xml
解决方法:
在pom.xml中添加如下代码:
<build>
...
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
5. 如何在eclipse中用maven编译
在eclipse中用maven编译的方法:
在项目中的“pom.xml”文件上点击右键,在弹出的菜单中选择“Run AS”à“Maveninstall”来编译和生成项目。如下图所示:
在编译和生成过程中,可以在“Console”面板中可以看到Maven编译过程的信息,如果编译和生成成功,可以在“Console”面板看到“BUILD SUCCESS”字样。
另外,在修改pom.xml文件中的相关jar包信息时,可能由于仓库中不存在,就会出现一些错误,这时,项目编译就可能存在一些问题。此时可通过“Maven clean”选项来清除编译,然后再修改pom.xml到正确情况。再通过“Maven install”来编译和生成。
6. 刚创建的maven项目,pom.xml的第一行就报错
解决方法:
首先确定你的电脑是否可以连接网络。
如果可以连接网络,在maven的本地库的路径下执行以下命令:
for/r%iin(*.lastUpdated)dodel%i
最后,尝试刷新maven工程,看是否可以成功。
(6)maven编译xml扩展阅读:
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。
Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司项目采用 Maven 的比例在持续增长。
Maven这个单词来自于意第绪语(犹太语),意为知识的积累,最初在Jakata Turbine项目中用来简化构建过程。当时有一些项目(有各自Ant build文件),仅有细微的差别,而JAR文件都由CVS来维护。于是希望有一种标准化的方式构建项目,一个清晰的方式定义项目的组成,一个容易的方式发布项目的信息,以及一种简单的方式在多个项目中共享JARs。
常用命令:
1.mvn archetype:generate 创建Maven
2.项目mvn compile 编译源代码
3.mvn deploy 发布项目
4.mvn test-compile 编译测试源代码
5.mvn test 运行应用程序中的单元测试
6.mvn site 生成项目相关信息的网站
7.mvn clean 清除项目目录中的生成结果
8.mvn package 根据项目生成的jar
9.mvn install 在本地Repository中安装jar
10.mvn eclipse:eclipse 生成eclipse项目文件
11.mvnjetty:run 启动jetty服务
12.mvntomcat:run 启动tomcat服务
参考资料:网络:Maven
7. 用maven编译项目时出现如下问题
在/etc/profile配置java的环境变量: 你的mvn 项目是用哪个版本的jdk.,就要配置那个版本的jdk。
强制保存文件命令:w !sudo tee %
此时在进入项目执行:$ git pull origin master
继续mvn clean install
8. 如何在maven pom.xml文件中设置Java编译器版本
1,生成3个目录/lib,/conf,/bin目录
2,把所有的jar目录编译、拷贝到/lib目录(包括maven的jar包和lib目录下的jar,以及编译的jar包)
3,把所有的启动脚本从工程根目录拷贝到/bin目录
4,把所有的配置文件从src/main/resources拷贝到/conf
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">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test.common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test.common</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 这里省略n行 -->
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<!-- 把src/main/resources目录下所有的文件拷贝到conf目录中 -->
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/conf</targetPath>
</resource>
<!-- 把lib目录下所有的文件拷贝到lib目录中
(可能有些jar包没有办法在maven中找到,需要放在lib目录中) -->
<resource>
<directory>lib</directory>
<targetPath>${project.build.directory}/lib</targetPath>
</resource>
<!-- 把放在根目录下的脚本文件.sh,.bat拷贝到bin目录中 -->
<resource>
<directory>.</directory>
<includes>
<include>**/*.sh</include>
<include>**/*.bat</include>
</includes>
<targetPath>${project.build.directory}/bin</targetPath>
</resource>
</resources>
<plugins>
<!-- 用于编译的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<!-- 如果配置了JAVA_HOME,下面应该可以不用配 -->
<executable>C:\Program Files (x86)\Java\jdk1.8.0_91\bin\javac.exe</executable>
</configuration>
</plugin>
<!-- 用于生成jar包的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- 把生成的jar包放在lib目录下(和其他所有jar包一起) -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<excludes>
<!-- 排除掉一些文件,不要放到jar包中,
这里是为了排除掉src/main/resources中的文件(它们应该放到conf目录)
这里只能指定要排除的目标文件,而不能指定源文件,虽然不够完美,但是基本能达到目的。 -->
<exclude>*.xml</exclude>
<exclude>*.properties</exclude>
</excludes>
</configuration>
</plugin>
<!-- 用于拷贝maven依赖的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>-dependencies</id>
<phase>package</phase>
<goals>
<goal>-dependencies</goal>
</goals>
<configuration>
<!-- 把依赖的所有maven jar包拷贝到lib目录中(这样所有的jar包都在lib目录中) -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- 用于拷贝resource的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 配置生成源代码jar的plugin -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
<encoding>UTF-8</encoding>
<!-- 配置源代码jar文件的存放路径,和其他jar文件一起放在lib目录 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
然后执行maven package打包。如果是eclipse,在Project Explorer-> Run As –> Maven Build… –>在Goals中输入package,点Run进行编译。
9. 怎样解决maven里编译时包的依赖有关问题
一、导出到默认目录 targed/dependency
从Maven项目中导出项目依赖的jar包:进入工程pom.xml 所在的目录下,执行如下命令:
mvn dependency:-dependencies
或在eclipse中,选择项目的pom.xml文件,点击右键菜单中的Run As,见下图红框中,在弹出的Configuration窗口中,输入 dependency:-dependencies后,点击运行
maven项目所依赖的jar包会导出到targed/dependency目录中。
二、导出到自定义目录中
在maven项目下创建lib文件夹,输入以下命令:
mvn dependency:-dependencies -DoutputDirectory=lib
maven项目所依赖的jar包都会复制到项目目录下的lib目录下
三、设置依赖级别
同时可以设置依赖级别,通常使用compile级别
mvn dependency:-dependencies -DoutputDirectory=lib -DincludeScope=compile
10. maven编译时 修改了pom.xml中jar包版本号,但是依旧会下载老版本jar包,为什么
可能和ide有关系
调查方法:
用命令行 maven clean update 试试
如果是idea,pom-右键-重新加载