The finer points of runnable jar creation (Jersey & Genson) - java

I can create a runnable jar every time with Eclipse's Runnable Jar wizard. If I check the box for Eclipse to "Save as ANT script", then incorporate that code into build.xml and then have our GitLab CI process do a build & create a runnable jar, it runs, but it can't seem to find a class in that jar even though the .class file is in there.
I'm not sure where to start. The resulting jar files from the Eclipse build vs the standalone java/ant build are similar, but not exactly the same. A few things are out of order, but that's all I can put my finger on at the moment.
How can I start to hone in on this? My program is a Jersey web client. I'm using Genson and the error message I'm getting with the standalone jar build is
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json
But I can list the jar files and both have these entries
47 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/javax.ws.rs.ext.MessageBodyWriter
1220 Thu Aug 07 14:08:08 CDT 2014 javax/ws/rs/ext/MessageBodyWriter.class
Right now I can get around it by doing a build in Eclipse and manually deploying the file, but of course this isn't acceptable.
EDIT: Thanks to a helpful friend, I was pointed to the contents of META-INF/services. I don't know what it means, but here are the contents of that from both jars.
GitLab jar (get MessageBodyWriter error message)
0 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/
47 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/javax.json.spi.JsonProvider
47 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/javax.ws.rs.ext.MessageBodyReader
47 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/javax.ws.rs.ext.MessageBodyWriter
47 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/javax.ws.rs.ext.Providers
50 Sun Mar 27 22:23:48 CDT 2016 META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable
61 Fri May 27 19:08:18 CDT 2016 META-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator
60 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable
67 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/javax.servlet.ServletContainerInitializer
67 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/org.glassfish.jersey.servlet.spi.AsyncContextDelegateProvider
63 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/org.glassfish.jersey.servlet.spi.FilterUrlMappingsProvider
56 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable
56 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/javax.ws.rs.ext.RuntimeDelegate
73 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable
137 Thu Oct 27 14:32:12 CDT 2016 META-INF/services/org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable
855 Sun Oct 02 11:14:44 CDT 2016 META-INF/services/javax.annotation.processing.Processor
Eclipse jar (works)
0 Tue Dec 13 08:55:42 CST 2016 META-INF/services/
47 Tue Dec 13 08:55:42 CST 2016 META-INF/services/javax.json.spi.JsonProvider
47 Tue Dec 13 08:55:42 CST 2016 META-INF/services/javax.ws.rs.ext.MessageBodyReader
47 Tue Dec 13 08:55:42 CST 2016 META-INF/services/javax.ws.rs.ext.MessageBodyWriter
47 Tue Dec 13 08:55:42 CST 2016 META-INF/services/javax.ws.rs.ext.Providers
50 Tue Dec 13 08:55:42 CST 2016 META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable
61 Tue Dec 13 08:55:42 CST 2016 META-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator
67 Tue Dec 13 08:55:42 CST 2016 META-INF/services/javax.servlet.ServletContainerInitializer
67 Tue Dec 13 08:55:42 CST 2016 META-INF/services/org.glassfish.jersey.servlet.spi.AsyncContextDelegateProvider
63 Tue Dec 13 08:55:42 CST 2016 META-INF/services/org.glassfish.jersey.servlet.spi.FilterUrlMappingsProvider
56 Tue Dec 13 08:55:42 CST 2016 META-INF/services/org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable
56 Tue Dec 13 08:55:42 CST 2016 META-INF/services/javax.ws.rs.ext.RuntimeDelegate
855 Tue Dec 13 08:55:44 CST 2016 META-INF/services/javax.annotation.processing.Processor
EDIT3: The contents of each duplicate
org.glassfish.jersey.internal.spi.AutoDiscoverable (3)
com.owlike.genson.ext.jaxrs.JerseyAutoDiscoverable
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
org.glassfish.jersey.server.filter.internal.ServerFiltersAutoDiscoverable
org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable (2)
org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
Versus the "good" jar file, built by Eclipse, which has no duplicates:
in org.glassfish.jersey.internal.spi.AutoDiscoverable
com.owlike.genson.ext.jaxrs.JerseyAutoDiscoverable
I guess I'll plow through other META-INF things, so see what can be seen.
in org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable
org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable

Related

kafka connect to Google BigQuery throws error java.lang.NoClassDefFoundError: org/apache/kafka/common/config/ConfigDef$CaseInsensitiveValidString

I am trying to stream from a Kafka topic to Google BigQuery. My connect-standalone.properties file is as follows:
bootstrap.servers=rhes75:9092,rhes75:9093,rhes75:9094,rhes564:9092,rhes564:9093,rhes564:9094,rhes76:9092,rhes76:9093,rhes76:9094
key.converter=org.apache.kafka.connect.storage.StringConverter
##value.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=org.apache.kafka.connect.json.JsonConverter
key.converter.schemas.enable=false
value.converter.schemas.enable=false
##internal.key.converter=org.apache.kafka.connect.json.JsonConverter
internal.value.converter=org.apache.kafka.connect.json.JsonConverter
internal.key.converter=org.apache.kafka.connect.storage.StringConverter
##internal.value.converter=org.apache.kafka.connect.storage.StringConverter
internal.key.converter.schemas.enable=false
internal.value.converter.schemas.enable=false
offset.storage.file.filename=/tmp/connect_bq.offsets
offset.flush.interval.ms=10000
#plugin.path=/d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins
plugin.path=/d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins/wepay-kafka-connect-bigquery-2.1.0
and my bigquery-sink.properties is as below
name=bigquery-sink
connector.type=bigquery-connector
connector.class=com.wepay.kafka.connect.bigquery.BigQuerySinkConnector
defaultDataset=test
project=axial-glow-224522
topics=md
autoCreateTables=false
gcsBucketName=tmp_storage_bucket
queueSize=-1
bigQueryRetry=0
bigQueryRetryWait=1000
bigQueryMessageTimePartitioning=false
bigQueryPartitionDecorator=true
timePartitioningType=DAY
keySource=FILE
keyfile=/home/hduser/xyz.json
sanitizeTopics=false
schemaRetriever=com.wepay.kafka.connect.bigquery.retrieve.IdentitySchemaRetriever
threadPoolSize=10
allBQFieldsNullable=false
avroDataCacheSize=100
batchLoadIntervalSec=120
convertDoubleSpecialValues=false
enableBatchLoad=false
upsertEnabled=false
deleteEnabled=false
mergeIntervalMs=60_000L
mergeRecordsThreshold=-1
autoCreateBucket=true
allowNewBigQueryFields=false
allowBigQueryRequiredFieldRelaxation=false
allowSchemaUnionization=false
kafkaDataFieldName=null
kafkaKeyFieldName=null
I run the code as below
#!/bin/ksh
unset CLASSPATH
export CLASSPATH=/d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins/wepay-kafka-connect-bigquery-2.1.0/lib:$KAFKA_HOME/libs
export KAFKA_DEBUG=y
$KAFKA_HOME/bin/connect-standalone.sh \
/d4T/hduser/bigquery-kafka-connect-sink/etc/connect-standalone.properties \
/d4T/hduser/bigquery-kafka-connect-sink/etc/bigquery-sink.properties
It comes back with this error
[2021-03-13 18:17:38,499] INFO Started o.e.j.s.ServletContextHandler#2ecf5915{/,null,AVAILABLE} (org.eclipse.jetty.server.handler.ContextHandler:744)
[2021-03-13 18:17:38,503] INFO Started http_8083#6badba10{HTTP/1.1}{0.0.0.0:8083} (org.eclipse.jetty.server.ServerConnector:266)
[2021-03-13 18:17:38,503] INFO Started #1981ms (org.eclipse.jetty.server.Server:379)
[2021-03-13 18:17:38,503] INFO Advertised URI: http://50.140.197.220:8083/ (org.apache.kafka.connect.runtime.rest.RestServer:248)
[2021-03-13 18:17:38,503] INFO REST server listening at http://50.140.197.220:8083/, advertising URL http://50.140.197.220:8083/ (org.apache.kafka.connect.runtime.rest.RestServer:207)
[2021-03-13 18:17:38,503] INFO Kafka Connect started (org.apache.kafka.connect.runtime.Connect:55)
[2021-03-13 18:17:38,518] ERROR Stopping after connector error (org.apache.kafka.connect.cli.ConnectStandalone:113)
java.lang.NoClassDefFoundError: org/apache/kafka/common/config/ConfigDef$CaseInsensitiveValidString
at com.wepay.kafka.connect.bigquery.config.BigQuerySinkConfig.getConfig(BigQuerySinkConfig.java:505)
at com.wepay.kafka.connect.bigquery.BigQuerySinkConnector.config(BigQuerySinkConnector.java:79)
at org.apache.kafka.connect.connector.Connector.validate(Connector.java:132)
at org.apache.kafka.connect.runtime.AbstractHerder.validateConnectorConfig(AbstractHerder.java:277)
at org.apache.kafka.connect.runtime.standalone.StandaloneHerder.putConnectorConfig(StandaloneHerder.java:164)
at org.apache.kafka.connect.cli.ConnectStandalone.main(ConnectStandalone.java:107)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.config.ConfigDef$CaseInsensitiveValidString
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.apache.kafka.connect.runtime.isolation.PluginClassLoader.loadClass(PluginClassLoader.java:104)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
It complains about not finding this class
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.config.ConfigDef$CaseInsensitiveValidString
However, under directory
/d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins/wepay-kafka-connect-bigquery-2.1.0/lib
it is in kafka-clients-1.1.0.jar
jar tvf kafka-clients-1.1.0.jar|grep org.apache.kafka.common.config.ConfigDef$CaseInsensitiveValidString
2051 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$1.class
1175 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$2.class
2876 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$3.class
1132 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$4.class
1801 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$CompositeValidator.class
3274 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$ConfigKey.class
1255 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$Importance.class
1104 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$NonEmptyString.class
2144 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$NonEmptyStringWithoutControlChars.class
922 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$NonNullValidator.class
2072 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$Range.class
583 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$Recommender.class
1513 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$Type.class
293 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$Validator.class
1943 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$ValidList.class
2196 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$ValidString.class
1269 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef$Width.class
34225 Fri Mar 23 22:54:26 GMT 2018 org/apache/kafka/common/config/ConfigDef.class
So I have no idea what is missing in here?
The jars loaded are shown below
jvm.classpath = /d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins/wepay-kafka-connect-bigquery-2.1.0/lib:/data6/hduser/kafka_2.12-1.1.0/libs:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/aopalliance-repackaged-2.5.0-b32.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/argparse4j-0.7.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/commons-lang3-3.5.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/connect-api-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/connect-file-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/connect-json-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/connect-runtime-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/connect-transforms-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/guava-20.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/hk2-api-2.5.0-b32.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/hk2-locator-2.5.0-b32.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/hk2-utils-2.5.0-b32.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jackson-annotations-2.9.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jackson-core-2.9.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jackson-databind-2.9.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jackson-jaxrs-base-2.9.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jackson-jaxrs-json-provider-2.9.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jackson-module-jaxb-annotations-2.9.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javassist-3.20.0-GA.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javassist-3.21.0-GA.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javax.annotation-api-1.2.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javax.inject-1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javax.inject-2.5.0-b32.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javax.servlet-api-3.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/javax.ws.rs-api-2.0.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-client-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-common-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-container-servlet-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-container-servlet-core-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-guava-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-media-jaxb-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jersey-server-2.25.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-client-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-continuation-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-http-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-io-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-security-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-server-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-servlet-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-servlets-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jetty-util-9.2.24.v20180105.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/jopt-simple-5.0.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka-clients-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka-log4j-appender-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka-streams-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka-streams-examples-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka-streams-test-utils-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka-tools-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka_2.12-1.1.0-sources.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka_2.12-1.1.0-test-sources.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/kafka_2.12-1.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/log4j-1.2.17.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/lz4-java-1.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/maven-artifact-3.5.2.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/metrics-core-2.2.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/osgi-resource-locator-1.0.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/plexus-utils-3.1.0.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/reflections-0.9.11.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/rocksdbjni-5.7.3.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/scala-library-2.12.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/scala-logging_2.12-3.7.2.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/scala-reflect-2.12.4.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/slf4j-api-1.7.25.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/slf4j-log4j12-1.7.25.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/snappy-java-1.1.7.1.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/validation-api-1.1.0.Final.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/zkclient-0.10.jar:/data6/hduser/kafka_2.12-1.1.0/bin/../libs/zookeeper-3.4.10.jar
os.spec = Linux, amd64, 3.10.0-1062.9.1.el7.x86_64
os.vcpus = 6
Thanks all.
I was using an older Kafka version.
I upgraded Kafka in the cluster from kafka_2.12-1.1.0 to the latest stable version kafka_2.12-2.7.0. I also upgraded zookeeper from zookeeper-3.4.6 to apache-zookeeper-3.6.2-bin version.
In addition in the run file I added the following:
#!/bin/ksh
unset CLASSPATH
export CLASSPATH=/d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins:$KAFKA_HOME/libs
$KAFKA_HOME/bin/connect-standalone.sh \
/d4T/hduser/bigquery-kafka-connect-sink/etc/connect-standalone.properties \
/d4T/hduser/bigquery-kafka-connect-sink/etc/bigquery-sink.properties
where the first part of CLASSPATH comes from plugins
plugin.path=/d4T/hduser/bigquery-kafka-connect-sink/share/kafka/plugins
This solved the issue

Runnable jar (ExceptionInInitializerError)

I've got a problem which I understand but I have no idea how to fix it.
I have a class in my project that contains static fields with images or sounds so that I can use them everywhere without recreating variables every time.
One of the fields for reference (they are all the same):
public static ImageIcon mainMenuBg = new ImageIcon(Resources.class.getResource("img/menubg.png"));
Now my problem is that it works fine in Eclipse when I run it, but when I export the project to a runnable JAR, nothing happens. I then went in the command window and ran it from there, and I have this ExceptionInInitializerError due to my images. Basically, none of the images are recognized at runtime, so if I remove every image call, it works.
Also, it is worth noting that when exporting, the list of Main classes doesn't really update. If I change the project's main's name, it isn't added to the list. Might it be a problem with my main class specifically? If so, how can I fix that? I tried to recreate it already but nothing changed.
Could someone enlighten me about this problem, please?
Here is the printstacktrace:
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at Client.<init>(Client.java:53)
at Client$1.run(Client.java:37)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at Ressources.<clinit>(Ressources.java:41)
... 16 more
Where the lines pointed are lines in which I'm trying to load an image from my resources class.
Also, all of my classes are in the same package, the default one.
Finally, here is the 'jar tvf ...' command's result:
153 Tue Jan 13 21:43:36 CET 2015 META-INF/MANIFEST.MF
0 Tue Jan 13 21:43:36 CET 2015 org/
0 Tue Jan 13 21:43:36 CET 2015 org/eclipse/
0 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/
0 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/
0 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/
978 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/JIJC
onstants.class
714 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/JarR
srcLoader$ManifestInfo.class
4735 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/JarR
srcLoader.class
1505 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/Rsrc
URLConnection.class
1841 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/Rsrc
URLStreamHandler.class
1149 Tue Jan 13 21:43:36 CET 2015 org/eclipse/jdt/internal/jarinjarloader/Rsrc
URLStreamHandlerFactory.class
1495 Tue Jan 13 21:43:06 CET 2015 ChatPrive$1.class
1792 Tue Jan 13 21:43:06 CET 2015 ChatPrive$2.class
1596 Tue Jan 13 21:43:06 CET 2015 ChatPrive$3.class
1897 Tue Jan 13 21:43:06 CET 2015 ChatPrive$4.class
1553 Tue Jan 13 21:43:06 CET 2015 ChatPrive$5.class
7565 Tue Jan 13 21:43:06 CET 2015 ChatPrive.class
2680 Tue Jan 13 21:43:06 CET 2015 Tour.class
9003 Tue Jan 13 21:43:06 CET 2015 Move.class
2622 Tue Jan 13 21:43:06 CET 2015 InfosPartie.class
1448 Tue Jan 13 21:43:06 CET 2015 Message.class
3262 Tue Jan 13 21:43:06 CET 2015 Roi.class
1464 Tue Jan 13 21:43:06 CET 2015 Case.class
987 Tue Jan 13 21:43:06 CET 2015 JoueurIA.class
750 Tue Jan 13 21:43:06 CET 2015 MenuCopie$1.class
1307 Tue Jan 13 21:43:06 CET 2015 MenuCopie$2.class
2992 Tue Jan 13 21:43:06 CET 2015 MenuCopie.class
7882 Tue Jan 13 21:43:06 CET 2015 ReceptionClient.class
1138 Tue Jan 13 21:43:06 CET 2015 Chat$1.class
851 Tue Jan 13 21:43:06 CET 2015 Chat$2.class
3835 Tue Jan 13 21:43:06 CET 2015 Chat.class
2263 Tue Jan 13 21:43:06 CET 2015 Fou.class
832 Tue Jan 13 21:43:06 CET 2015 MenuPromotion$1.class
2081 Tue Jan 13 21:43:06 CET 2015 MenuPromotion$2.class
1401 Tue Jan 13 21:43:06 CET 2015 MenuPromotion$3.class
1216 Tue Jan 13 21:43:06 CET 2015 MenuPromotion$4.class
1216 Tue Jan 13 21:43:06 CET 2015 MenuPromotion$5.class
1216 Tue Jan 13 21:43:06 CET 2015 MenuPromotion$6.class
4231 Tue Jan 13 21:43:06 CET 2015 MenuPromotion.class
1501 Tue Jan 13 21:43:06 CET 2015 Jeu$1.class
825 Tue Jan 13 21:43:06 CET 2015 Jeu$2.class
10677 Tue Jan 13 21:43:06 CET 2015 Jeu.class
1457 Tue Jan 13 21:43:06 CET 2015 ChatAll$1.class
1570 Tue Jan 13 21:43:06 CET 2015 ChatAll$2.class
1344 Tue Jan 13 21:43:06 CET 2015 ChatAll$3.class
1914 Tue Jan 13 21:43:06 CET 2015 ChatAll$4.class
1527 Tue Jan 13 21:43:06 CET 2015 ChatAll$5.class
9326 Tue Jan 13 21:43:06 CET 2015 ChatAll.class
1135 Tue Jan 13 21:43:06 CET 2015 PanelInfo$1.class
1337 Tue Jan 13 21:43:06 CET 2015 PanelInfo$10.class
1164 Tue Jan 13 21:43:06 CET 2015 PanelInfo$11.class
963 Tue Jan 13 21:43:06 CET 2015 PanelInfo$12.class
1335 Tue Jan 13 21:43:06 CET 2015 PanelInfo$13.class
963 Tue Jan 13 21:43:06 CET 2015 PanelInfo$14.class
830 Tue Jan 13 21:43:06 CET 2015 PanelInfo$15.class
829 Tue Jan 13 21:43:06 CET 2015 PanelInfo$16.class
1435 Tue Jan 13 21:43:06 CET 2015 PanelInfo$2.class
576 Tue Jan 13 21:43:06 CET 2015 PanelInfo$3.class
1748 Tue Jan 13 21:43:06 CET 2015 PanelInfo$4.class
1356 Tue Jan 13 21:43:06 CET 2015 PanelInfo$5.class
1552 Tue Jan 13 21:43:06 CET 2015 PanelInfo$6.class
1556 Tue Jan 13 21:43:06 CET 2015 PanelInfo$7.class
945 Tue Jan 13 21:43:06 CET 2015 PanelInfo$8.class
1437 Tue Jan 13 21:43:06 CET 2015 PanelInfo$9.class
16765 Tue Jan 13 21:43:06 CET 2015 PanelInfo.class
1176 Tue Jan 13 21:43:06 CET 2015 MenuUtilisateurs$1.class
1173 Tue Jan 13 21:43:06 CET 2015 MenuUtilisateurs$2.class
1753 Tue Jan 13 21:43:06 CET 2015 MenuUtilisateurs$3.class
2228 Tue Jan 13 21:43:06 CET 2015 MenuUtilisateurs$4.class
2071 Tue Jan 13 21:43:06 CET 2015 MenuUtilisateurs.class
3996 Tue Jan 13 21:43:06 CET 2015 Piece.class
3830 Tue Jan 13 21:43:06 CET 2015 PartieSolo.class
3300 Tue Jan 13 21:43:06 CET 2015 ConnexionClient.class
1160 Tue Jan 13 21:43:06 CET 2015 EchecGUI$1.class
8154 Tue Jan 13 21:43:06 CET 2015 EchecGUI.class
6844 Tue Jan 13 21:43:06 CET 2015 Joueur.class
677 Tue Jan 13 21:43:06 CET 2015 Client$1.class
834 Tue Jan 13 21:43:06 CET 2015 Client$2.class
2718 Tue Jan 13 21:43:06 CET 2015 Client$3.class
1041 Tue Jan 13 21:43:06 CET 2015 Client$4.class
1008 Tue Jan 13 21:43:06 CET 2015 Client$5.class
983 Tue Jan 13 21:43:06 CET 2015 Client$6.class
1096 Tue Jan 13 21:43:06 CET 2015 Client$7.class
4611 Tue Jan 13 21:43:06 CET 2015 Client.class
2783 Tue Jan 13 21:43:06 CET 2015 Pion.class
663 Tue Jan 13 21:43:06 CET 2015 JoueurReel.class
1620 Tue Jan 13 21:43:06 CET 2015 MessagePrive.class
6302 Tue Jan 13 21:43:06 CET 2015 PartieEnLigne.class
1911 Tue Jan 13 21:43:06 CET 2015 Cheval.class
6817 Tue Jan 13 21:43:06 CET 2015 Ressources.class
1235 Tue Jan 13 21:43:06 CET 2015 NotificationMessage$1.class
1348 Tue Jan 13 21:43:06 CET 2015 NotificationMessage.class
3835 Tue Jan 13 21:43:06 CET 2015 PartieAmi.class
1355 Tue Jan 13 21:43:06 CET 2015 EmissionClient.class
2999 Tue Jan 13 21:43:06 CET 2015 Reine.class
0 Tue Jan 13 20:55:48 CET 2015 img/
945 Sun Jan 11 19:40:24 CET 2015 img/attaque.png
196863 Fri Jan 09 22:59:04 CET 2015 img/board.png
595046 Sun Jan 11 22:04:40 CET 2015 img/board1.png
631303 Sat Jan 10 00:14:04 CET 2015 img/board2.png
440 Sun Jan 11 22:32:28 CET 2015 img/boutonchat.png
413 Sun Jan 11 22:32:46 CET 2015 img/boutonchatsel.png
735 Sun Jan 11 21:53:46 CET 2015 img/boutonrecommencer.png
793 Sun Jan 11 21:54:52 CET 2015 img/boutonrecommencersel.png
258 Wed Dec 24 17:28:54 CET 2014 img/caseCible.png
224 Sat Jan 10 18:23:04 CET 2015 img/casePleinePoss.png
1100 Sat Jan 10 18:14:06 CET 2015 img/caseSelectionnee.png
224 Sat Jan 10 18:14:30 CET 2015 img/caseVidePoss.png
5962 Wed Dec 24 17:28:54 CET 2014 img/chevalblanc.png
1203 Mon Jan 12 21:37:44 CET 2015 img/chevalblancmort.png
1106 Sun Jan 11 00:40:14 CET 2015 img/chevalblancpromo.png
5720 Wed Dec 24 17:28:54 CET 2014 img/chevalnoir.png
1214 Mon Jan 12 21:37:44 CET 2015 img/chevalnoirmort.png
1119 Sun Jan 11 00:40:50 CET 2015 img/chevalnoirpromo.png
8080 Mon Jan 12 20:44:20 CET 2015 img/echec.png
29956 Mon Jan 12 00:08:06 CET 2015 img/ecranpause.png
3736 Thu Jan 08 00:14:42 CET 2015 img/fondlabel.png
5783 Sun Jan 11 19:04:14 CET 2015 img/fondlabelblanc.png
6968 Sun Jan 11 19:04:18 CET 2015 img/fondlabelnoir.png
5327 Sun Jan 11 22:22:52 CET 2015 img/footer.png
4087 Wed Dec 24 17:28:54 CET 2014 img/foublanc.png
1024 Mon Jan 12 21:37:46 CET 2015 img/foublancmort.png
887 Sun Jan 11 00:43:04 CET 2015 img/foublancpromo.png
3987 Wed Dec 24 17:28:54 CET 2014 img/founoir.png
1010 Mon Jan 12 21:37:48 CET 2015 img/founoirmort.png
864 Sun Jan 11 00:43:24 CET 2015 img/founoirpromo.png
10904 Sun Jan 11 01:19:48 CET 2015 img/historique.png
260917 Tue Jan 13 20:55:48 CET 2015 img/menubg.png
127477 Tue Jan 13 19:30:36 CET 2015 img/panelinfobg.png
270 Sun Jan 11 22:13:34 CET 2015 img/pause.png
256 Sun Jan 11 22:13:48 CET 2015 img/pausesel.png
3817 Mon Jan 12 01:41:14 CET 2015 img/pionblanc.png
979 Mon Jan 12 21:37:50 CET 2015 img/pionblancmort.png
3813 Thu Jan 08 00:39:10 CET 2015 img/pionnoir.png
992 Mon Jan 12 21:37:42 CET 2015 img/pionnoirmort.png
379 Sun Jan 11 23:00:42 CET 2015 img/play.png
377 Sun Jan 11 23:00:28 CET 2015 img/playsel.png
37986 Mon Jan 12 01:17:54 CET 2015 img/promobg.png
449 Sun Jan 11 22:58:14 CET 2015 img/redo.png
439 Sun Jan 11 22:58:32 CET 2015 img/redosel.png
5292 Wed Dec 24 17:28:54 CET 2014 img/reineblanc.png
1245 Mon Jan 12 21:37:54 CET 2015 img/reineblancmort.png
1140 Sun Jan 11 00:41:18 CET 2015 img/reineblancpromo.png
5185 Wed Dec 24 17:28:54 CET 2014 img/reinenoir.png
1222 Mon Jan 12 22:24:28 CET 2015 img/reinenoirmort.png
1115 Sun Jan 11 00:41:40 CET 2015 img/reinenoirpromo.png
5809 Mon Jan 12 00:11:32 CET 2015 img/reprendreBtn.png
4946 Mon Jan 12 00:12:56 CET 2015 img/reprendreBtnsel.png
5889 Wed Dec 24 17:28:54 CET 2014 img/roiblanc.png
5717 Wed Dec 24 17:28:54 CET 2014 img/roinoir.png
2152 Sun Jan 11 00:57:20 CET 2015 img/roque.png
2144 Sun Jan 11 19:26:50 CET 2015 img/roqueblanc.png
2099 Sun Jan 11 19:26:16 CET 2015 img/roquenoir.png
529 Mon Jan 12 21:58:58 CET 2015 img/sonoff.png
503 Mon Jan 12 21:59:24 CET 2015 img/sonoffsel.png
686 Mon Jan 12 21:59:36 CET 2015 img/sonon.png
623 Mon Jan 12 21:59:52 CET 2015 img/sononsel.png
395 Sun Jan 11 22:43:30 CET 2015 img/surrender.png
357 Sun Jan 11 22:43:46 CET 2015 img/surrendersel.png
849 Mon Jan 12 19:40:22 CET 2015 img/tooltip.png
4564 Wed Dec 24 17:28:54 CET 2014 img/tourblanc.png
1146 Mon Jan 12 21:38:00 CET 2015 img/tourblancmort.png
1008 Sun Jan 11 00:42:16 CET 2015 img/tourblancpromo.png
4528 Wed Dec 24 17:28:54 CET 2014 img/tournoir.png
1135 Mon Jan 12 21:38:04 CET 2015 img/tournoirmort.png
986 Sun Jan 11 00:42:42 CET 2015 img/tournoirpromo.png
453 Sun Jan 11 22:57:06 CET 2015 img/undo.png
441 Sun Jan 11 22:56:48 CET 2015 img/undosel.png
1326 Mon Jan 12 01:13:52 CET 2015 img/valider.png
1393 Mon Jan 12 01:19:40 CET 2015 img/validersel.png
0 Tue Jan 13 18:50:36 CET 2015 snd/
2248748 Mon Jan 12 23:35:38 CET 2015 snd/ambiancefeu.wav
77868 Mon Jan 12 23:32:06 CET 2015 snd/attaque.wav
25988 Tue Jan 13 00:08:06 CET 2015 snd/boutonclic.wav
397356 Mon Jan 12 21:02:50 CET 2015 snd/echec.wav
43342 Sun Jan 11 23:59:36 CET 2015 snd/hover.wav
319532 Wed Jan 07 00:43:04 CET 2015 snd/message.wav
108464 Mon Jan 12 23:45:02 CET 2015 snd/played.wav
606552 Tue Jan 13 18:50:36 CET 2015 snd/promotion.wav
112156 Sat Jan 10 19:06:50 CET 2015 snd/select.wav
After digging in documentation around I think that is possible that the problem is that you are using a relative path instead of an absolute path as explained here:
[http://www.thinkplexx.com/learn/howto/java/system/java-resource-loading-explained-absolute-and-relative-names-difference-between-classloader-and-class-resource-loading]
So please try:
ImageIcon mainMenuBg = new ImageIcon(Resources.class.getResource("/img/menubg.png"));
Use somthing like this for your images.
ClassLoader cldr = this.getClass().getClassLoader();
URL picture = cldr.getResource("files/gcf.jpg");
ImageIcon mainMenuBg = new ImageIcon(picture);
And for the sounds.
ClassLoader cldr = this.getClass().getClassLoader();
URL musicurl = cldr.getResource("files/gcf.wav");
try{
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicurl);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
}
catch (Exception ex){
System.out.println("loading ??");
}
(import java.net.*; for the URL class)
Put your /files folder into the /src folder and create your JAR.

maven test-jar: src/test/resources/file present but could not found by test

I have module structure like
external_services/pom.xml
ifs/pom.xml
src/main/java
src/main/java/resources
src/test/java
src/test/java/resources/sample.json
inventory/pom.xml
ifs/pom.xml
src/main/java
src/main/java/resources
src/test/java/MyTest.java
In this MyTest.java I need to get sample.json since I want that to be shared across, so in business/pom.xml I add the following
<dependency>
<groupId>com.org.my_services.external_services</groupId>
<artifactId>ifs</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
so now when I run the test, I see
file:/Users/harith/.m2/repository/com/org/my_services/external_services/ifs/1.0-SNAPSHOT/ifs-1.0-SNAPSHOT-tests.jar!/sample.json (No such file or directory)
However, when I look at jar ifs-1.0-SNAPSHOT-tests.jar, I see it there
jar -tvf /Users/harith/.m2/repository/com/org/pryme_services/federated_services/ifs/1.0-SNAPSHOT/ifs-1.0-SNAPSHOT-tests.jar
0 Wed May 07 09:47:36 PDT 2014 META-INF/
131 Wed May 07 09:47:34 PDT 2014 META-INF/MANIFEST.MF
0 Wed May 07 09:47:34 PDT 2014 com/
0 Wed May 07 09:47:34 PDT 2014 com/org/
0 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/
0 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/
0 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/
0 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/configuration/
892 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/configuration/DevelopmentContextConfiguration.class
888 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/configuration/ProductionContextConfiguration.class
2381 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/IFSClientTest.class
1422 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/InventoryRESTClientTest.class
1033 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/MockIfsClient$1.class
2350 Wed May 07 09:47:34 PDT 2014 com/org/pryme_services/external_services/ifs/MockIfsClient.class
142315 Wed May 07 09:47:34 PDT 2014 sample.json // <-- here
0 Wed May 07 09:47:36 PDT 2014 META-INF/maven/
0 Wed May 07 09:47:36 PDT 2014 META-INF/maven/com.org.pryme_services.federated_services/
0 Wed May 07 09:47:36 PDT 2014 META-INF/maven/com.org.pryme_services.federated_services/ifs/
2391 Wed May 07 09:45:36 PDT 2014 META-INF/maven/com.org.pryme_services.federated_services/ifs/pom.xml
138 Wed May 07 09:47:34 PDT 2014 META-INF/maven/com.org.pryme_services.federated_services/ifs/pom.properties
The way it is used in class is
inventoryPriceDetails = mapper.readValue(new File(getClass().getResource("/getInventoryAndPrice.json").getPath()), new TypeReference<List<InventoryPriceDetail>>() {
});
I am not sure what I am missing, can some one please help?
there are a couple of things:
1)
external_services/pom.xml
ifs/pom.xml
src/main/java
src/main/java/resources
src/test/java
src/test/java/resources/sample.json
but maven expects
external_services/pom.xml
ifs/pom.xml
src/main/java
src/main/resources
src/test/java
src/test/resources/sample.json
"resource" parallel to "java". In your case "resource" is a package.
2) The file is called "sample.json" but you look for "getInventoryAndPrice.json"
3) new File does not work on a Path. You need getResourceAsStream() to extract data from a jar.
(If you want to work with paths you need to work with the nio classes, not File)

Problems packaging apps with Jersey deps into jars

My group publishes executable jars (not applets, just to be clear) for nearly all of our functionality. One of our new executables is a Web service client that relies on Jersey. I'm trying to use the automatic POJO mapping facility to unmarshal responses (i.e., I have JSONConfiguration.FEATURE_POJO_MAPPING set to true in the ClientConfig) but when I execute the jar I get the "I don't know how to unmarshal this response" message:
SEVERE: A message body reader for Java class edu.mit.broad.picard.bass.GetSite, and Java type class edu.mit.broad.picard.bass.GetSite, and MIME media type application/json was not found
The app works just fine if I run it from my IDE (IntelliJ). I'm assuming it's a problem with the way in which the jar file is packaged but I don't know the details of Jersey (or Jackson, for that matter) well enough to get this fixed. Any hints?
This is Java 1.7, Jersey bundle 1.17.1 and Jackson 1.9.13. All the com/sun/**/* and org/codehaus/**/* files are being included in the jar.
Thanks for your help!!
Edit:
I checked the META-INF dir for the needed .../services dir. Here's what's in it:
cm59f-0fa:zamboni jrose$ jar tvf GenerateGetSite.jar | grep META-INF | grep services
0 Thu Aug 15 10:43:32 EDT 2013 META-INF/services/
0 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.server.impl.model.method.dispatch.ResourceMethodDispatchProvider
514 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.HeaderDelegateProvider
563 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.StringReaderProvider
147 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.container.ContainerProvider
60 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.container.ContainerRequestFilter
0 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.container.ContainerResponseFilter
377 Wed Feb 27 20:17:28 EST 2013 META-INF/services/com.sun.jersey.spi.container.ResourceMethodCustomInvokerDispatchProvider
376 Wed Feb 27 20:17:28 EST 2013 META-INF/services/com.sun.jersey.spi.container.ResourceMethodDispatchProvider
64 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.container.WebApplicationProvider
267 Thu Feb 28 15:29:04 EST 2013 META-INF/services/com.sun.jersey.spi.inject.InjectableProvider
44 Wed Feb 27 20:17:06 EST 2013 META-INF/services/javax.enterprise.inject.spi.Extension
882 Mon Dec 19 14:53:22 EST 2011 META-INF/services/javax.script.ScriptEngineFactory
79 Wed Feb 27 20:17:06 EST 2013 META-INF/services/javax.servlet.ServletContainerInitializer
2880 Thu Feb 28 15:29:04 EST 2013 META-INF/services/javax.ws.rs.ext.MessageBodyReader
2654 Thu Feb 28 15:29:04 EST 2013 META-INF/services/javax.ws.rs.ext.MessageBodyWriter
56 Thu Feb 28 15:29:04 EST 2013 META-INF/services/javax.ws.rs.ext.RuntimeDelegate`
My guess would be that you are creating one jar that contains the contents of all of your jar dependencies. If this is the case, the issue is probably due to improper construction of your one jar. Jersey relies on resources in META-INF/services for its proper operation. You need to make sure that the contents of META-INF/services get merged into your one jar.
One option that is working for me is the maven-shade-plugin, which includes a transformer that does exactly this merging:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</plugin>

Reading txt file from jar fails but reading image works

I have an issue which has been bothering me for days... I checked similar questions but couldn't find a solution.
I use NetBeans IDE. I build the project jar file i.e "Clock.jar" which contains a "clock" named folder in which some images, a text file and all project classes are found.
The following code for creating an image icon works
return new ImageIcon(getClass().getResource("/clock/button_close.png"));
But the following code for reading the text file fails
InputStream name = getClass().getResourceAsStream("/clock/input.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(name));
As you may have guessed the NullPointer Exception is thrown meaning probably it couln't locate the file.
But how come the image icon is constructed successfully (by passing it the URL returned from getResource) but the txt file cannot be found (by passing it an input stream from getResourceAsStream).
Thanks in advance, for any answer ( I mean it :) )
jar -tvf Clock.jar
0 Wed May 15 14:44:36 EEST 2013 META-INF/
202 Wed May 15 14:44:34 EEST 2013 META-INF/MANIFEST.MF
0 Wed May 15 14:44:36 EEST 2013 clock/
649 Wed May 15 14:44:36 EEST 2013 clock/Clock$1$1.class
789 Wed May 15 14:44:36 EEST 2013 clock/Clock$1.class
2026 Wed May 15 14:44:36 EEST 2013 clock/Clock.class
709 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$1.class
830 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$2.class
750 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$3.class
713 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$4.class
741 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$5.class
708 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$6.class
1081 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$7.class
981 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog$8.class
9640 Wed May 15 14:44:36 EEST 2013 clock/ClockDialog.class
702 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame$1.class
708 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame$2.class
734 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame$3.class
743 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame$4.class
531 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame$5.class
1046 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame$6.class
9464 Wed May 15 14:44:36 EEST 2013 clock/ClockFrame.class
782 Wed May 15 14:44:36 EEST 2013 clock/ErrorReporter.class
1826 Wed May 15 14:44:36 EEST 2013 clock/IconButton.class
2693 Wed May 15 14:44:36 EEST 2013 clock/MessagePool.class
2824 Wed May 15 14:44:36 EEST 2013 clock/SystemInfo.class
2212 Wed May 15 14:44:36 EEST 2013 clock/button_close.png
6540 Wed May 15 14:44:36 EEST 2013 clock/button_close_highlighted.png
5668 Wed May 15 14:44:36 EEST 2013 clock/input.txt
Looking at the source again closely, try..
URL url = getClass().getResource("/clock/input.txt");
InputStream name = url.openStream();
I recall that the Class::getResourceAsStream variant deals with paths slightly differently than simply Class::getResource - I am sure it should work for the latter one.

Categories

Resources