掌握maven的诀窍。下载commons-cli。未编译的Apache cli帮助器。
我创建了一个新的maven项目,并删除了其中所有未编译的代码。如下所示:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-
quickstart -DinteractiveMode=false这样就创建了:
commons-cli/
src/
main/
java/
cli/
*.java <- all the java code.现在运行:
mvn archetype:create-from-project这将创建:
generated-sources/
archetype/
src/
main/
test/
target/
pom.xml在此pom.xml中:
<groupId>com.company.app</groupId>
<artifactId>test-archetype</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>test-archetype</name>现在:
cd target/generated-sources/archetype/和
mvn clean install现在我的.m2/文件夹中有一个jar,我不能使用它作为依赖。因为代码是未编译的。
我的问题是:
我如何才能在我的本地代码库中添加一个带有编译和可用代码(.class)的.jar?不需要java代码就可以使用它。
我怎么能只将java代码添加到我的repo中,就像maven-archetype-quickstart一样?
非常感谢。
发布于 2016-10-26 20:20:21
你的问题有些令人困惑,但我会尽我所能回答:
原型是项目的蓝图:您可以使用它们来创建新项目,但不需要在其中放置太多源代码。
您可以通过调用mvn clean install来创建编译后的jar。它将带有已编译类的jar写入本地存储库。如果您构建了这样的jar,您可以为"sources“和"javadoc”添加侧工件。这些也将被放入本地存储库中。
发布于 2016-10-26 23:04:15
明白了。
这比我想象的要简单。而不是上面的例子。我从以下几点开始
mvn archetype:generate
-DgroupId=[your project's group id]
-DartifactId=[your project's artifact id]
-DarchetypeArtifactId=maven-archetype-archetype将代码放入文件中。
然后清除etc.并编译:
mvn clean install并修改
src/main/resources/META-INF/maven/archetype.xml打包的编译代码:
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org
/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="commons-cli"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin
/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>org/apache/commons/cli</directory>
<includes>
<include>**/*.class</include>
<!--
<include>**/*.html</include>
-->
</includes>
</fileSet>
<!--
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
-->只需编写代码:
<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-
plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-
plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-
1.0.0.xsd">
<id>quickstart</id>
<sources>
<source>src/main/java/*.java</source>
</sources>
<testSources>
<source>src/test/java/*.java</source>
</testSources>
</archetype>代码和打包:
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org
/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="commons-cli"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin
/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>**/*.html</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>这就是archetype.xml中的配置...我还没测试过呢。但这应该能起到作用。我希望。:)谢谢JF Meier。
https://stackoverflow.com/questions/40258702
复制相似问题