2013-03-27 86 views
1

我试图打印到数字组成的字符串,控制台和资本M.它是这样的:无法打印包含数字和字母'M'的字符串。为什么?

System.out.println("blah"); 
System.out.println("123M"); 
System.out.println("blah blah"); 

,结果是

blah 
blah blah 

所以println("123M")甚至没有被执行,因为没有空两个人之间的界限。位数和组合无关紧要,但如果在'M'之后有任何字母或'M'后面有非空白字符,则会打印字符串。

在java 1.7.0_03-b05和另外两个(不知道版本)上试过。 谢谢你的任何线索。

更新: 问题出现在maven项目中。

下面是该截图:

enter image description here

另一个更新:

Charlee Chitsuk的一篇关于POM我改变矿井:

<build> 
    <plugins> 
    <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <configuration> 
     <archive> 
      <manifest> 
      <mainClass>javaapplication4.JavaApplication4</mainClass> 
      </manifest> 
     </archive> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 

mvn clean compile assembly:single我终于收到了正常工作的jar 。 为什么它不能与exec-maven-plugin一起工作对我来说仍然是个谜。

+5

你确定它不工作?我刚刚检查了它对我的工作...... – Radan 2013-03-27 15:26:25

+5

你在第二行添加后忘了重新编译它吗? – rm5248 2013-03-27 15:28:36

+0

我问三个人在工作,试图证实他们的问题。 – 2013-03-27 15:29:40

回答

2

我写了这个班,得到了一个线索。它只在Maven项目中失败。

在这种情况下,您几乎可以确定所运行的不是您认为正在运行的代码。这是唯一合理的解释。

0

我注意到,您正在使用org.codehaus.mojo:exec-maven-plugin:1.2:exec来执行JavaApplication4.java。那么我想你pom.xml可能看起来像

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
     <goals> 
      <goal>exec</goal> 
     </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <executable>java</executable> 
     <arguments> 
     <argument>-classpath</argument> 
     <!-- automatically creates the classpath using all project dependencies, 
      also adding the project build directory --> 
     <classpath/> 
     <argument>javaapplication4.JavaApplication4</argument> 
     ... 
     </arguments> 
    </configuration> 
    </plugin> 

build and clean使用Eclipse Menumvn clean install完全不同。通常I'using以下步骤在Eclipse中使用Maven: -

  1. 右击在项目选择Run As ----> Maven clean
  2. 右击在项目选择Run As ----> Maven testRun As ----> Maven install

我想通知您检查org.codehaus.mojo:exec-maven-plugin配置并尝试使用步骤1清理项目。然后再次运行您的课程。

我希望这可能有所帮助。

+0

我使用NetBeans,并确定我使用了maven自定义目标,然后键入'clean install'。这没有帮助,但看看我的第一篇文章更新。 – 2013-03-28 10:25:56