在maven项目中包含xml文件

0mkxixxg  于 2023-03-01  发布在  Maven
关注(0)|答案(2)|浏览(190)

我有一个maven pom文件要从如下结构构建:
Package 1
--1.java
--2.java
--packageMetaInfo.xml
程序包2
--21.java
--22.java
--packageMetaInfo.xml
当我进行maven编译时,xml文件不会进入目标。
maven-compiler-plugin 3.5.1 -除非我通过<exclusions>排除xmls,否则我会收到错误消息“Fatal error compiling:所有编译单元必须是SOURCE类型-〉”maven-compiler-plugin 2.0.1 -编译但跳过xml
有没有一种方法可以把XML文件包含在我的jar中。
x.jar
Package 1
--1.class
--2.class
--packageMetaInfo.xml
程序包2
--21.class
--22.class
--packageMetaInfo.xml

  • 我知道在XML中包含源文件可能不是Maven的标准,但我正在开发一个特定的产品,需要在输入和输出中维护这种结构。
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.incent</groupId>
  <artifactId>Release-4.3.0.1.0.0001</artifactId>
  <name>AAA Custom code</name>
  <version>2.4.0.1</version>  

  <properties>
        <ormb.cmccb.path>./Active_Repository/CMCCB</ormb.cmccb.path>
        <ormb.customcode.path>${ormb.cmccb.path}/data</ormb.customcode.path>
        <ormb.release.name>AAA-4.3.0.1.0.0001</ormb.release.name>
        <ormb.target.path>./target</ormb.target.path>
        <ormb.output.path>Release-${ormb.release.name}/Application/${ormb.release.name}/CMCCB</ormb.output.path>
        <ormb.serverfile.output.relpath>./target/server</ormb.serverfile.output.relpath>    
    <build.number>SNAPSHOT</build.number>
  </properties>


 <dependencies>

    <dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>5.0.3</version>
</dependency>

    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>icu4j</groupId>
        <artifactId>icu4j</artifactId>
        <version>49.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.2</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>wlfullclient</groupId>
        <artifactId>wlfullclient</artifactId>
        <version>10.3.4.0</version>
        <type>jar</type>
    </dependency>
    </dependencies>

  <build>

    <sourceDirectory>${ormb.customcode.path}/java</sourceDirectory>  

    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <encoding>UTF-8</encoding>
        </configuration>
        <executions>
           <execution>
            <id>copy-cm</id>
            <phase>install</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${ormb.customcode.path}/etc/lib</outputDirectory>
                <overwrite>true</overwrite>
                <resources>
                    <resource>
                        <directory>${ormb.target.path}</directory>
                        <includes>
                            <include>cm.jar</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
            </execution>
            <execution>
                <id>copy-mwpackage</id>
                <phase>install</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${ormb.serverfile.output.relpath}</outputDirectory>
                <overwrite>true</overwrite>
                <resources>
                    <resource>
                        <directory>${ormb.target.path}</directory>
                        <includes>
                            <include>Release-${ormb.release.name}.zip</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
            </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <encoding>ISO-8859-1</encoding> 
            <source>1.7</source>
            <target>1.7</target>
          <includes>
            <include>**/cm/**</include> 
          </includes>
          <excludes>
            <exclude>**/*.xml</exclude>
          </excludes>
        <resources>
            <resource>
            <directory>${ormb.customcode.path}/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            </resource>
        </resources>

        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
         <executions>
         <execution>
            <id>create-cm</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>Active_Repository/assembly/executable.xml</descriptor>
                </descriptors>
                <finalName>cm</finalName>
                 <manifest>
                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                </manifest>
                <archive>
                    <manifestEntries>
                        <Specification-Title>${project.name}</Specification-Title>
                        <Specification-Version>${project.version}</Specification-Version>
                        <Implementation-Version>${build.number}</Implementation-Version>
                    </manifestEntries>
                </archive>
            </configuration>
            </execution>
            <execution>
            <id>create-distro</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>Active_Repository/assembly/dist.xml</descriptor>
              </descriptors>
              <finalName>custom-action-dist</finalName>
              <appendAssemblyId>false</appendAssemblyId>
              <finalName>Release-${ormb.release.name}</finalName>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
bejyjqdl

bejyjqdl1#

我也遇到了同样的问题,我想把fxml和java文件保存在同一个文件夹中(我使用的scenebuilder需要把fxml和java文件放在同一个地方)。
下面是我在pom.xml中的解决方案:

<resources>
    <resource>
        <directory>src/main/resources</directory>
    </resource>
    <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.fxml</include>
        </includes>
  </resource>        
</resources>
xuo3flqw

xuo3flqw2#

如果您希望xml文件包含在JAR文件中,那么将它们存储在resources文件夹中,而不是java。
假设它们在src/main/java中,尝试将它们移动到src/main/resources中,src/main/resources中的任何内容都将与.class文件沿着打包到JAR文件中。

相关问题