我试图构建这个例子。https:/github.comoltzenJavaCppExample。 构建成功后,当我运行:java de.oltzen.javacppexample.Abc时,显示 "无法加载或找到主类"。
视频教程 (https:/www.youtube.comwatch?v=LZrrqZLhtmw)使用Eclipse和它运行的程序与Run as .Java应用程序。
POM文件是否缺少了什么?
我试着在POM中添加这个插件,但它没有工作,我是在JavaCppExampletargetclass中执行的。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>de.oltzen.javacppexample.Abc</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
我从JavaCppExampletargetclasses执行:-。
classes文件夹包含包文件夹:deoltzenjavacppexample最后一个文件夹包含类文件Abc.class。
所以我运行命令:java de.oltzen.javacppexample.Abc。
目标文件夹包含:1) classes [包含包的文件夹] 2) JavaCppExample.jar3) maven-archiver4) maven-status。
请帮忙
如果你只想通过maven运行你的prgramm,那么就使用exec-maven-plugin。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>de.oltzen.javacppexample.Abc</mainClass>
</configuration>
</plugin>
在这里探索更多=>。https:/www.mojohaus.orgexec-maven-pluginindex.html
如果你想构建& 运行为jar,那么使用汇编插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<descriptors>
<descriptor>${project.basedir}/assembly/assembly.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>de.oltzen.javacppexample.Abc</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
探索更多关于Maven汇编插件,根据自己的需求进行定制。
我为maven复制依赖关系添加了以下插件,并执行了以下操作 java -jar javaCppExample.jar。 [from target folder]就成功了。谢谢大家!
[只需使用 mvn 清洁安装]
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>de.oltzen.javacppexample.Abc</mainClass>
</manifest>
</archive>
</configuration>
</plugin>