Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在pom.xml中指定换行符_Java_Maven_Newline_Pom.xml - Fatal编程技术网

Java 在pom.xml中指定换行符

Java 在pom.xml中指定换行符,java,maven,newline,pom.xml,Java,Maven,Newline,Pom.xml,我需要生成一个包含项目依赖项jar的文件。 这可以通过dependeny插件完成。 请参见以下pom中的片段: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10&l

我需要生成一个包含项目依赖项jar的文件。 这可以通过dependeny插件完成。 请参见以下pom中的片段:

    <plugin>                   
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.10</version>   
        <execution>            
          <id>list-dependencies</id>
          <phase>package</phase>
          <goals>              
            <goal>build-classpath</goal>
          </goals>             
          <configuration>
            <prefix></prefix>
            <outputFile>target/modules-list.txt</outputFile>
            <pathSeparator>\n</pathSeparator>                                                                                                                       
          </configuration>  
        </execution>           
      </executions>            
    </plugin>                  

org.apache.maven.plugins
maven依赖插件
2.10
列出依赖项
包裹
构建类路径
target/modules-list.txt
\n
但是,由于我需要将每个jar放在单独的一行中,所以我尝试将
pathselector
指定为换行符。然而,这是行不通的。我没有找到在pom中指定换行符的有用方法


关于如何实现这一点有什么想法吗?

Maven正在修剪您的
值,这会导致一个空值,因为行分隔符被视为空白。然后,由于没有值,Maven会返回使用默认值。我看不到任何简单的方法来解决这种行为

还有一些其他的选择。你可以考虑使用目标:

pom.xml

<plugin>                   
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.10</version>
  <executions>
    <execution>
      <id>list-dependencies</id>
      <phase>package</phase>
      <goals>              
        <goal>list</goal>
      </goals>             
      <configuration>
        <outputFile>target/modules-list.txt</outputFile>
      </configuration>
    </execution>
  </executions>
</plugin>                  
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.10</version>
  <executions>
    <execution>
      <id>list-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>build-classpath</goal>
      </goals>
      <configuration>
        <outputFile>target/modules-list.txt</outputFile>
        <pathSeparator>_${line.separator}</pathSeparator>
      </configuration>
    </execution>
  </executions>
</plugin>
这是Maven工件ID,而不是jar文件名。可以说,这实际上更有价值,因为输出不会在运行构建的不同机器之间改变。(jar文件将使用绝对路径,在不同的机器上可能会有所不同。)

如果它确实必须是jar文件名而不是Maven工件ID,那么您可以通过向
值中注入非空白字符来拼凑一些东西,这样即使在Maven修剪该值之后,仍然有一些东西可以覆盖默认的路径分隔符

pom.xml

<plugin>                   
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.10</version>
  <executions>
    <execution>
      <id>list-dependencies</id>
      <phase>package</phase>
      <goals>              
        <goal>list</goal>
      </goals>             
      <configuration>
        <outputFile>target/modules-list.txt</outputFile>
      </configuration>
    </execution>
  </executions>
</plugin>                  
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.10</version>
  <executions>
    <execution>
      <id>list-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>build-classpath</goal>
      </goals>
      <configuration>
        <outputFile>target/modules-list.txt</outputFile>
        <pathSeparator>_${line.separator}</pathSeparator>
      </configuration>
    </execution>
  </executions>
</plugin>
不幸的是,这给你留下了丑陋的底线。如果你想清理这些,那么你需要另一个构建步骤来清理它们。一种方法是在
生成资源
阶段生成此文件,然后在
处理资源
阶段使用进行令牌替换


最后,如果您只是为了文档的目的需要这些信息,请考虑使用../p>在XML中提供的站点文档,您可以使用以下转义序列来指定换行符-<代码>和γx0a;<代码>

不幸的是,正如您已经提到的,
值被删除了所有的前导和尾随空格,从而导致一个空字符串值,导致插件使用其默认值

但是,可以在同一阶段使用Ant任务替换路径分隔符。比如说

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>list-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>build-classpath</goal>
                    </goals>
                    <configuration>
                        <prefix></prefix>
                        <outputFile>target/modules-list.txt</outputFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Replace path separator -->
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <replace file ="target/modules-list.txt" token="${path.separator}" value="${line.separator}" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

org.apache.maven.plugins
maven依赖插件
2.10
列出依赖项
包裹
构建类路径
target/modules-list.txt
maven antrun插件
1.8
包裹
跑

请注意,
不再在依赖项配置中定义。

可能需要包含换行符的CDATA部分work@Aaron不,没有。这就像直接在pom中输入新行一样。似乎这些空白字符都被删除了。我找到的唯一输入换行符的方法是用可打印字符包围换行符,这真的没有用。为什么需要这个?pathSeparator通常是操作系统用来分隔路径的分隔符。@Tunaki是的,构建类路径目标使用此pathSeparator构建类路径。然而,我不需要类路径,而是每行一个jar的列表。@Tunaki是的,这是akward,但这是最接近我需要的方法:所有依赖项的jar文件列表。这不是不幸的,这是设计的。这个目标旨在构建一些可用的类路径,而不是一般的花哨列表。@Tunaki,谢谢。我编辑它是为了删除您不喜欢的单词。@ChrisNauroth好吧,这是为了文档目的,但我仍然需要jar名称。我认为您添加一个下划线的方法是最合适的解决方案。因此,我接受你的回答。这不是不幸,这是故意的。这个目标是为了构建一个可用的类路径,而不是一个普通的花哨列表。@Tunaki我想这个解决方案是可以接受的,但是副词的选择不是吗?你希望我把它改成什么——唉,不幸,遗憾,还是悲伤?既然问题是我该怎么做?我没有回答“为什么我不能这样做?”而是掩饰地解释了专注于答案的原因。拉德兰的成绩不是因为进球的目的。除非包含
xml:space=“preserve”
属性,否则默认情况下会修剪
下的元素内容。谢谢你给我一个扩展的机会。@Frelling虽然你的建议可行,但我会按照ChrisNauroth描述的方式去做。但还是要感谢你的帮助。@radlan我感谢你的反馈;虽然我很好奇。我的答案——这本身就说明了问题——给了你想要的东西,但你却满足于有悬垂的下划线。考虑到其目的是为了文档,这意味着它将不仅仅由您阅读,您希望有人多久会质疑tr的重要性