Is it possible to rename a java class using Maven?
I'm using the Maven Archetype to generate new projects based on my model. I can set a new groupId, artifactId, and packages for each new project.
This is the current pom.xml inside target.
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>jar</packaging>
So, when I want to create a project Banana (artifactId) inside com.foo (groupId) , it's pretty possible. All I need to do is run: mvn archetype:generate (...arguments like groupId, artifactId, version)
It will generate a new project based on my archetype, renaming its packages, groupId, artifactId. But I also want to rename some java classes, thus:
ArchetypeApplication.java should be renamed to BananaApplication.java!
Is there some way to do that?
You can only specify a class name if the archetype supports this feature. For example: zk-archetype-theme defines the "theme-listener-class" property for this.
Related
I am new to maven and I'm confused about the difference between the artifactId and name.
What I know is that artifactId is the name of the artifact you are creating. I know that artifactId together with the groupId is use to uniquely identifies an artifact. So what is <name> purpose in POM. like the pom below I got from a site there is an artifactId and at the same time a <name>.
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
You are correct that the artifactId helps identify the project.
The name is simply a human-readable "friendly" name. It is not required for a basic setup.
From the Maven documentation,
artifactId: The artifactId is generally the name that the project is known by. Although the groupId is important, people within the group will rarely mention the groupId in discussion ... It, along with the groupId, create a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository.
The groupId, artifactId and version form a composite unique identifier (or coordinate) for this project. Each of these values has a fairly rigid naming convention that allows well organized groups, artifacts and versions.
The name is simply a readable name for the project and does not need to be unique or comply to the same conventions (so it can contain spaces and other characters).
The name is used for the project used by maven to build the artifact, while the artifact-id is used to identify the artifact that will be built.
For example:
This pom file definition for the rsts ear file:
Causes the rsts-ear project to be imported into Eclipse:
But creates the rsts_ear artifact in the nexus:
This means that the artifact-id, not the name, is referenced to include the artifact in the build as part of another artifact.
I want to build one jar that includes a child module which depends on other package of my own project.
The output one jar should include all the related class (both from jar and my own project's classes).So the child module's classes is the base classes that should be included in the output jar,and these import some classes of my own project.All the related classes in my own project should be included.
for more detail please visit How to automatically collect all related class into one jar (use maven)?
Here is what I already find:
<project>
<dependencies>
<dependency>
<scope>system</scope>
<systemPath>D:\how\to\write</systemPath>
<groupId>how.to.write</groupId>
<artifactId>how-to-write</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>java-source</type>
</dependency>
</dependencies>
</project>
The error message is : Could not find artifact how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT at specified path D:\how\to\write
the path D:\how\to\write contains my own project's classes that could support the build
Your maven dependency will look for a jar file with name how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT in D:\how\to\write directory. Since you do not have one, the build will fail.
If your own project does not use maven, then you should create a jar file and place it in D:\how\to\write location and rename it to how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT. Then your build mvn clean install will be success.
The command for creating jar file is jar cf jar-file input-file(s).
Have a look at this page on how to create a jar file
I am using mvn archetype:create-from-project within a manually created project
This project has both inherited and aggregated modules.
However when creating a new project based on this fresh archetype, the aggregated module pom file always finds itself injected with <parent>..</parent> attribute thus inheriting rather than being aggregated, which screws up the build order.
How can I prevent this aggregated module to be injected with <parent> tag?
It's actually not possible.
There's an open request for it on their JIRA from November 2011:
As mentioned in ARCHETYPE-110, the current implementation overwrites parent information if there are no existing parent definition inside the body of the pom.xml. So if we don't want such declaration we haven't no alternatives.
Source: https://jira.codehaus.org/browse/ARCHETYPE-393
I'm using the Apache Felix Maven Bundle Plugin to generate the OSGi metadata.
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
You can configure which packages are exported or you can use the default, which excludes packages such as *.impl.* and *.internal.*.
Is there a way to generate Javadoc only for the exported packages without having to duplicate this information?
Edit:
My current approach is that I set the excludePackageNames property (a Maven Javadoc Plugin property) manually and thus duplicate this information:
<excludePackageNames>*.internal.*:*.impl.*</excludePackageNames> <!-- used by Javadoc plugin --><!-- TODO: get this from OSGi meta data-->
http://sourceforge.net/p/drombler/drombler-oss-parent/ci/default/tree/pom.xml#l64
The Apache Maven bundle plugin is based on bndlib, which has its own plugin model. If a maven plugin model has class visibility to other maven plugins then it is easy to get this information. In the instructions in the pom register a plugin:
<instructions>
<_plugin>com.example.MyPlugin</_plugin>
</instruction>
In this bnd plugin, implement the AnalyzerPlugin interface
boolean analyzeJar(Analyzer analyzer) throws Exception {
doJavadoc( analyzer.getExportedPackages().keySet() );
}
I am not that familiar with maven plugins, since bnd will do dynamic class loader (yuck), it must be able to see your code.
I guess the best thing would be, if the Maven Bundle Plugin would provide a goal to generate the needed information.
I filed a new issue: https://issues.apache.org/jira/browse/FELIX-4181
I'm using maven to build a ".ear" project that resolves dependencies from a maven repository, and then packages them into an ear (that's probably a redundant sentence...).
When the dependencies show up in the ear file, they're named according to this format:
<artifactId>-<version>.<type>
I'd like them to be named:
<artifactId>.<type>
Can someone point me in the right direction?
If you're using the maven-assembly-plugin to build your ear, you can use the outputFileNameMapping property in your descriptor: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet
However, you're probably better off using the maven-ear-plugin, in which case you can customize the bundleFileName, as described here.
Set the finalName property. See http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html for more details