【发布时间】:2021-08-05 12:25:28
【问题描述】:
我有 Maven 项目
所有的java文件都位于src/test/java
我的 pom.xml 如下
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>manual-jar</id>
<goals>
<goal>jar</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<classifier>manual</classifier>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}-manual.lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
当我运行命令 mvn clean install -DskipTests 时,我在目标文件夹中创建了 jar 文件。
但是当我在其他项目中使用它时,带有cmets/multiline cmets的类文件下的方法jar中没有显示。请在这里帮忙。
这就是我在方法中的评论
/*
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute <a href="#{@link}">{@link "url"}</a>. The name
* argument is a specifier that is relative to the url argument.
* <p>
* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded. The graphics primitives
* that draw the image will incrementally paint on the screen.
*
* @param url an absolute URL giving the base location of the image
* @param name the location of the image, relative to the url argument
* @return the image at the specified URL
* @see String
*/
public String abc(String name, String url){
String c =name+url;
return c ;
}
【问题讨论】:
-
“jar 中包含的 cmets”到底是什么意思?您可以使用 maven 源插件来创建源工件。
-
将所有 Java 源代码放入
src/test/java是没有意义的。目录src/test/java仅用于测试正在运行的构建,但如果src/main/java中没有任何内容,则没有要测试的内容。 -
如果给定的
All the java files are located in src/test/java是真的,那么你就完全误解了 maven 的工作原理。正如@JFabianMeier 所描述的那样......将java文件移动到适当的位置。 -
@J Fabian Meier 和 @khmarbaise,我已经将所有内容从 src/test/java 移动到 src/main/java,当我现在构建这个项目时,我也获得了包含资源的包(我没有想要)当我在其他项目中使用这个 jar 时,也无法识别方法。
-
请在 github 或类似网站上创建一个示例项目以展示真实世界...这样更容易...
标签: java maven executable-jar