maven 要点整理

 Eclipse中调试

使用maven的一个方便之处是可以使用Jetty Plugin来运行web项目。只要maven jetty:run就可以把web项目跑起来了。只是很多时候我们都需要在IDE中进行调试。那如何在Eclipse中调试使用jetty Plugin的web项目呢?
    下面我们就来配置一下。

  1. 首先在Run->Externel Tools->Open Externel Tools Dialog.. 打开配置对话框,选中左边的Program节点,右键选择New然后再右边的配置里面输入Name信息,在Main tab下的Location选择你maven可执行文件的全路径(eg:/home/rory/apps/apache-maven-2.0.8/bin/mvn),Working Directory选择你的maven项目(eg:${workspace_loc:/guice-example}),Arguments里输入jetty:run。然后再切换到Environment tab。New 一下变量,name是
    MAVEN_OPTS
    value是
    -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y
    ok,这一步设置完毕,Apply一下,close关闭
  2. 接下来添加一个Debug,打开Run->Open Debug Dialog..打开Debug Dialog窗口,选中左边的Remote Java Application,右键New输入name,Project里选中要Debug的项目Connection Properties里的Host里设置成localhost,Port设置成上面配置的4000然后Apply一下就ok了。
  3. 接下来就可以开始调试了。首先启动第一步配置的Externel Tools配置,然后再运行第二步配置的Debug.就可以看到控制台有mvn jetty:run的输出了。接下来就开如Debug你的项目吧。:)

解决方案一:
原来,是${java.home}在作怪,eclipse 没有使用 JAVA_HOME



默认,eclipse 使用 C:"windows"system32"javaw.exe 作为 JVM,当然找不到tools.jar

解决方法如下:

修改 eclipse.exe 目录下的 eclipse.ini 指定vm,,注意 -vm后面不能有空格。
-vmD:\Program Files\Java\jdk1.6.0_23\bin\javaw.exe

-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
-XX:PermSize=64M
-XX:MaxPermSize=512M

解决方案二:

 

  • <properties>   
  • <project.build.sourceEncoding>UTF8</project.build.sourceEncoding>   
  •     <java.home>C:\Program Files\Java\jdk1.6.0_25</java.home>     
  •  </properties>   
  • <profiles>     
  •        <profile>     
  •            <id>default-tools.jar</id>     
  •            <activation>     
  •                <property>     
  •                    <name>java.vendor</name>     
  •                    <value>Sun Microsystems Inc.</value>     
  •                </property>     
  •            </activation>     
  •            <dependencies>     
  •                <dependency>     
  •                    <groupId>com.sun</groupId>     
  •                    <artifactId>tools</artifactId>     
  •                    <version>1.5.0</version>     
  •                    <scope>system</scope>     
  •                    <systemPath>${java.home}/lib/tools.jar</systemPath>     
  •                </dependency>     
  •            </dependencies>     
  •        </profile>     
  •    </profiles>     

 

参考:http://linjia880714.iteye.com/blog/1133883

http://www.blogjava.net/hello-yun/archive/2011/11/21/364409.html

总结:本人试用了之后没有解决问题,只能手工的将jdk下面的tools.jar拷贝到需要的目录下面制作成pom和jar来提供给eclipse使用。这属于m2e的bug,暂时没有其他解决方案(将tools.jar用mvn inststall安装到本地仓库)

 


<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>com.demo.test</groupId>
<artifactId>demo-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-maven</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/demo-plugin</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/demo-plugin/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy todir="${project.build.directory}/demo-plugin">
<fileset dir="${project.build.directory}" includes="**.jar" />
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
            <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-rar-plugin</artifactId>
             <version>2.3</version>
             <configuration>
                      <finalName>hello</finalName>
             <rarSourceDirectory>${project.build.directory}/demo-plugin</rarSourceDirectory>
             <filterRarSourceDirectory>true</filterRarSourceDirectory>
     </configuration>
            </plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings 
only. It has no influence on the Maven build itself. -->
<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.4,)
</versionRange>
<goals>
<goal>
copy-dependencies
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<resources>
  <resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
 </resource> 
</resources>
</build>
       <profiles>
<profile>
<id>a</id>
<activation>
   <activeByDefault>true</activeByDefault>
</activation>
<properties>
<dataBase>jdbc</dataBase>
<connectionUrl>http://192.168.10.11</connectionUrl>
</properties>
</profile>
<profile>
<id>b</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
        
</project>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值