Maven构建-类文件大小减小了

时间:2019-01-11 10:33:30

标签: java maven build

我正在尝试改造现有项目。 我能够构建EAR文件(因为必须在Websphere中进行部署),当我尝试使用管理控制台进行部署时-可以成功安装,但是应用程序无法正常工作,经过调查,我发现class files大小与参考EAR文件(旧的EAR文件)相比要小得多

我遵循的构建EAR文件的步骤

  1. 已安装M2E插件
  2. 配置为Maven
  3. lib文件夹添加 ALL 如下所示的jar文件(我读过,这不是推荐的方法,但是要完成项目,我必须这样做)< / li>
<dependency>
<groupId>JarFile</groupId>
<artifactId>JarFile</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/CRDBXMLExternal.jar</systemPath>
</dependency>
  1. 添加了相关插件(war, EAR)
  2. 清理构建并安装。
  3. ear文件已创建。 ear包含一个war文件,其中包含与项目相关的所有文件,包括classjsp等。

我将文件夹结构与现有EAR文件及其内容进行了比较,看起来都很不错。但是只有类文件的大小(不是全部,但超过80%)是变化的。我使用JD来decompile并查看代码,大多数代码不存在,包括imports

如果有人遇到类似问题,请告诉我这里做错了什么。

更多信息

有两个项目文件夹(均为Maven),一个将创建WAR,另一个在EAR pom.xml中创建EAR。 有依赖性

<dependency>
		<groupId>com.comp.abc</groupId>
		<artifactId>abc</artifactId>
		<version>1.0</version>
		<type>war</type>
	</dependency>

然后有一个插件

<build>
    <plugins>
		<plugin>
			<artifactId>maven-ear-plugin</artifactId>
			<version>2.10</version>
			<configuration>
				<version>5</version>
				<defaultLibBundleDir>lib</defaultLibBundleDir>
				<generatedDescriptorLocation>C:\COMP\Dev\may\repos\0.0.1-SNAPSHOT</generatedDescriptorLocation>
			</configuration>
		</plugin>      
    </plugins>
  </build>

添加WAR文件构建(删除了大多数依赖项,仅保留了一个样本)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>com.comp.abc</groupId>
	<artifactId>abc</artifactId>
	<version>1.0</version>
	<packaging>war</packaging>
	<name>ABC</name>
	<description>ABC</description>

	<dependencies>
		<!-- Local Repository -->
		<dependency>
			<groupId>com.ibm.ws.runtime</groupId>
			<artifactId>com.ibm.ws.runtime</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>${basedir}/WebContent/WEB-INF/lib/com.ibm.ws.runtime.jar</systemPath>
		</dependency>
	</dependencies>



	<repositories>
		<repository>
			<id>nexus-releases</id>
			<name>nexus</name>
			<url>http://abc-nexus.ldn.xyz.com:9080/nexus/content/groups/public/</url>
		</repository>
	</repositories>

	<build>
		<sourceDirectory>src</sourceDirectory>
		<resources>
			<resource>
				<directory>src</directory>
				<excludes>
					<exclude>**/*.java</exclude>
				</excludes>
			</resource>
		</resources>
		<plugins>			
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<!-- <warSourceDirectory>${project.basedir}\WebContent</warSourceDirectory> -->
					<warSourceDirectory>WebContent</warSourceDirectory>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

2 个答案:

答案 0 :(得分:0)

以上内容并未告诉Maven使用lib目录依赖项来打包EAR文件。它实际上告诉它在仅在编译时提供的现有JAR上创建本地依赖项。因此,在导出EAR时,它不包含任何JAR,因为它假定它们是在运行时提供的。

您应该使用打包EAR文件的maven-ear-plugin。您可以找到完整的文档here

  <plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <version>3.0.1</version>
  </plugin>

答案 1 :(得分:0)

问题是, web/WebContent/WEB-INF/classes尚未更新。 但我可以在classes路径下看到最新的web/target/classes。 现在正在检查为什么web/WebContent/WEB-INF/classes没有得到更新。

现在从以下链接获得了解决方案:- 在以下人员的帮助下解决了问题 https://coderanch.com/t/474423/ide/ecplise-doesn-create-classes-folder

步骤

右键单击您的项目->构建路径->配置构建路径->单击源选项卡->单击浏览(默认输出文件夹)。

浏览后,单击WebContent->选择WEB-INF->创建新文件夹(称为类)。它将打开新窗口。

将文件夹名称作为类。单击高级,并给出当前类文件夹的路径,即WEB-INF / classes。

完成此操作后,eclispe将重建您的项目,并在WEB-INF / classes目录中生成类。