muhmacit / onejar-maven-plugin

Automatically exported from code.google.com/p/onejar-maven-plugin
0 stars 0 forks source link

ClassCastException with one jar and java help #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Using java help from within one jar creates a class cast exception

//I initialize java help like this

ClassLoader cl = getClass().getClassLoader();

            URL hsURL = HelpSet.findHelpSet(cl, helpHS);
            hs = new HelpSet(null, hsURL);
            hb = hs.createHelpBroker();

//In the action to show the Java Help component 
System.out.println("Help");
        new CSH.DisplayHelpFromSource( hb );
        hb.setDisplayed(true);

What is the expected output? What do you see instead?

Uncaught error fetching image:
java.lang.ClassCastException: sun.misc.Launcher$AppClassLoader cannot be
cast to com.simontuffs.onejar.JarClassLoader
    at com.simontuffs.onejar.JarClassLoader.getByteStream(JarClassLoader.java:753)
    at com.simontuffs.onejar.Handler$1.getInputStream(Handler.java:50)
    at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:114)
    at
sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
    at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)

What version of the product are you using? On what operating system?

java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)

Linux pavilion 2.6.27.21-170.2.56.fc10.x86_64 #1 SMP Mon Mar 23 23:08:10
EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

<dependency>
  <groupId>javax.help</groupId>
  <artifactId>javahelp</artifactId>
  <version>2.0.02</version>
</dependency> 
..
<groupId>org.dstovall</groupId>
                <artifactId>onejar-maven-plugin</artifactId>
                <version>1.4.1</version>
                <executions>
                    <execution>
                        <configuration>
                            <!-- Optional -->
                            <onejarVersion>0.96</onejarVersion>

Please provide any additional information below.

Original issue reported on code.google.com by hazlorea...@gmail.com on 10 Jun 2009 at 3:05

GoogleCodeExporter commented 8 years ago
Hi!

Thank you for taking time to submit this issue.

I have never used Java Help before, and having downloaded it now and looking at 
their
samples, I can't get them to run easily with Maven.

Could you please put together a minimal Maven project using Java Help, which 
triggers
the problem you are describing? It needs to /work/ /without/ 
onejar-maven-plugin, and
to /not/ work /with/ onejar-maven-plugin. That would help very much in 
debugging this
issue.

Please submit it in the simplest way you know, for example on github.com, or 
zipping
it up and attaching to this issue, or simple copy/pasting every file's contents
directly in a comment here.

Thank you in advance!
/Hugo

Original comment by hugo.josefson.old@gmail.com on 12 Jun 2009 at 5:41

GoogleCodeExporter commented 8 years ago

Original comment by hugo.josefson.old@gmail.com on 12 Jun 2009 at 6:58

GoogleCodeExporter commented 8 years ago
Hi, I also had this problem but using Hibernate's EntityManager implementation. 
The 
problem occurs when Hibernate is trying to scan a jar for entities.

java.lang.ClassCastException: sun.misc.Launcher$AppClassLoader cannot be cast 
to 
com.simontuffs.onejar.JarClassLoader
        at 
com.simontuffs.onejar.JarClassLoader.getByteStream(JarClassLoader.java:753)
        at com.simontuffs.onejar.Handler$1.getInputStream(Handler.java:50)
        at java.net.URL.openStream(Unknown Source)
        at 
org.hibernate.ejb.packaging.InputStreamZippedJarVisitor.doProcessElements(InputS
tream
ZippedJarVisitor.java:37)
        at 
org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVis
itor.
java:139)
        at 
org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:287
)
        at 
org.hibernate.ejb.Ejb3Configuration.addMetadataFromVisitor(Ejb3Configuration.jav
a:282
)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:247)
        at 
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersi
stenc
e.java:125)
        at 
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)

I actually made a change to the JarClassLoader in the OneJar project itself to 
get 
round this problem.

        if (result == null && delegateToParent)
        {
            ClassLoader parentClassLoader = getParent();

            // JarClassLoader cannot satisfy requests for actual jar 
files themselves so it must delegate to it's
            // parent. However, the "parent" is not always a 
JarClassLoader.
            if (parentClassLoader instanceof JarClassLoader)
                result = ((JarClassLoader) 
parentClassLoader).getByteStream(resource);
            else
                result = 
parentClassLoader.getResourceAsStream(resource);
        }

I'm not sure where (or how) to submit this patch but it works for us.

James.

Original comment by bruce.n...@gmail.com on 16 Nov 2009 at 2:24

GoogleCodeExporter commented 8 years ago
Hi James,

They host the One-JAR project at SourceForge. Here is the project's Tracker 
page:
http://sourceforge.net/tracker/?group_id=111153

You should probably file it in the "Patches" tracker. I'm sure they will 
appreciate
your patch.

Thanks,
Hugo

Original comment by hugo.josefson.old@gmail.com on 16 Nov 2009 at 6:18

GoogleCodeExporter commented 8 years ago
It appears somebody has already submitted a patch but that was 2 years ago!
http://sourceforge.net/tracker/?func=detail&aid=1805547&group_id=111153&atid=658
459

I had assumed the project was now hosted here hence posting but I guess that is 
not the 
case. Shame because it's a useful packaging option.

Original comment by bruce.n...@gmail.com on 17 Nov 2009 at 10:05

GoogleCodeExporter commented 8 years ago
Huh. No, we're not that good at classpath hacking :) We just do the Maven 
plugin,
which collects the One-JAR together with your jars and your dependencies.

You could try contacting Simon Tuffs directly, to figure out the status and let 
him
know about the patches. Maybe he has just been really busy lately..?

Thanks,
Hugo

Original comment by hugo.josefson.old@gmail.com on 17 Nov 2009 at 7:52

GoogleCodeExporter commented 8 years ago
Marking this issue as WontFix, because it seems we can't fix it here in the 
plugin.
It's a classpath thing within the upstream One-JAR project itself.

Original comment by hugo.josefson.old@gmail.com on 17 Nov 2009 at 7:53

GoogleCodeExporter commented 8 years ago
Hmmm... Ok, so if I fix one-jar, how can I get the plugin to use the fixed 
version?

Original comment by obast...@gmail.com on 17 Dec 2009 at 6:53

GoogleCodeExporter commented 8 years ago
Hi All:

As you say, I've been really busy recently, but your activity in building this 
maven 
plugin has given urgency to rolling out a new version of One-JAR, incorporating 
various patches and fixes that have been submitted.

Thanks for producing this useful maven plugin, I'll try to make sure One-JAR is 
up-
to-date.

Simon.

Original comment by simontu...@gmail.com on 18 Dec 2009 at 5:21

GoogleCodeExporter commented 8 years ago
Hi Simon,

Thanks for commenting.

I gave you committer permissions on this project, so that you can (if you want 
to)
tag and change status on issues here too. For example when you see issues here 
which
are actually in the scope of the One-JAR project, you might want to set their 
status
here on the Maven plugin as WontFix, and add a comment about how/where they can 
work
with you to get it fixed upstream.

Again, thanks for staying involved! There's quite a bunch of us who enjoy and 
rely on
your great One-JAR project :)

Happy new year!
/Hugo

Original comment by hugo.josefson.old@gmail.com on 31 Dec 2009 at 1:04

GoogleCodeExporter commented 8 years ago
This should be fixed in OneJAR 0.97, which is included in onejar-maven-plugin 
1.4.3. 
Please try <version>1.4.3</version> for the onejar-maven-plugin in your pom.

Thanks,
Hugo

Original comment by hugo.josefson.old@gmail.com on 31 May 2010 at 6:59