Re:
Remi Forax <[email protected]> Sun, 27 Aug 2017 17:31:33 +0200 (CEST)
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
Hi Robert,
ModuleVisitor has a method visitEnd() that is called after having seen all values,
so a code like this should work.
new ModuleVisitor(ASM6, parent) {
private String mainClass = moduleMainClass; // default main class
public void visitMainClass(String mainClass) {
this.mainClass = mainClass; // extracted main class
}
public void visitEnd() {
super.visitMainClass(mainClass); // set the main class
}
};
cheers,
Rémi
----- Mail original -----
> De: "Robert Scholte" <[email protected]>
> À: "asm" <[email protected]>
> Envoyé: Samedi 26 Août 2017 18:53:56
> Objet: [asm]
> Hi,
>
> I'm trying to add some extra information to the module-info.class like done by
> the jar executable of the jdk. In my case plexus-archiver is responsible for
> creating the jar.
>
> With the following code I get the following error: CONSTANT_Class at entry 9
> has illegal character: '.'
>
> How should I change the following code?
>
> final String moduleVersion = "1.0.0"
>
> final String moduleMainClass = "org.foo.bar.Main";
>
> ClassReader reader = new ClassReader( is );
>
> ClassWriter writer = new
> ClassWriter( ClassWriter.COMPUTE_FRAMES );
>
> ClassVisitor classVisitor = new ClassVisitor( Opcodes.ASM6,
> writer )
> {
> @Override
> public ModuleVisitor visitModule( String name, int access,
> String __ )
> {
> ModuleVisitor parent = super.visitModule( name,
> access, moduleVersion );
>
> ModuleVisitor visitor = new
> ModuleVisitor( Opcodes.ASM6, parent )
> {
> boolean visitMainClassCalled;
>
> @Override
> public void visitMainClass( String __ )
> {
> if ( !visitMainClassCalled )
> {
> super.visitMainClass( moduleMainClass );
> visitMainClassCalled = true;
> }
> }
> };
> visitor.visitMainClass( moduleMainClass );
>
> return visitor;
> }
> };
>
> reader.accept( classVisitor, Opcodes.ASM6 );
>
> return new ByteArrayInputStream( writer.toByteArray() );
>
>
> --
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws