JAXB JSON JAR Runtime List reader not available - java

I have a small project created with IntelliJ IDEA, using Jersey.
I already created the server part working just fine and hosted on a GAE server.
I try to connect to it via a Jersey Client, and here comes the strange stuff.
Everything works fine if I run my application from inside the IntelliJ IDEA. However, once I run the jar JSON support seems to be gone, however XML works. Any ideas?
I feel I need to mention that the jersey-json is packaged with the generated jar.
Here it is the jar file in question. You'll need both the jar and the dll file, one near the other and just run it.
The Console Output (Error): https://docs.google.com/open?id=0B42XvjSlpDCtTTdwQl9MSTBlQ0U
The JAR file I used (all dependencies extracted into it). Any JRE6 may run it. https://docs.google.com/open?id=0B42XvjSlpDCtTVNUQTQ4SXFCcDg
The DLL required for the JAR (although, it should work without this too): https://docs.google.com/open?id=0B42XvjSlpDCtNXpabVk5RDkyRW8
And here's the source code on the github (public): https://github.com/gaborbernat/fs_viewer
Finally, I attach a picture with the settings of the artifact (JAR) generate rules.
Thanks for your support, :)

please see http://java.net/projects/jersey/sources/svn/content/trunk/jersey/jersey-tests/src/test/java/com/sun/jersey/impl/json/ListOfJAXBBeanTest.java?rev=5698
(your usecase can be extracted from there; the point is that you need to configure Jersey Client to be able to handle json by a) registering JAXBContextResolver or b) explicitly adding MessageBodyWriters (jackson))
And dont forget to use GenericEntity (as in linked test).

Related

How do I access Java resources in a Grails project?

Grails newbie here. My application is in Grails, my IDE is IntelliJ IDEA. I configured my project (in IntelliJ) to say that my resources folder is under root\src\resources. I have an image file in there that I need to load into an InputStream / BufferedImage. However I can't seem to get to those resources from my Grails controller. This is what I was trying:
def image = this.getClass().getClassLoader().getResourceAsStream("image.png")
But that just returns null. I use this exact same convention in Java projects (well, except I have to declare image being of type InputStream), and it does work there. I was under the impression that I could essentially drop Java code in a Grails project and it should just work. What do I need to do differently to get this to work in my Grails controller? I need to access that static resource file.
If you mark a directory as a source directory in IntelliJ IDEA, Grails won't know about it. You have to configure Grails properly by either adding your new directory as a source directory or move the resource to one of the standard source directories.
I've never actually added a new source directory myself, but the answer to this stackoverflow question looks promising.
Other than that, you can just add resources to any source directory and it will be included, for example: grails-app/conf, src/java, src/groovy and more. In addition, any file in web-app/META-INF/classes will also be in the classpath of the application. The last one is great to know about if you need to copy a java or groovy source file (i.e. just copy, no compilation).
Try this
servletContext.getResourceAsStream("/WEB-INF/resources/yourfile")

Creating a Jar File Containing Another Jar File

I've created an Android project that does some very simple network stuff. This project is standalone, and I've successfully exported it as a jar file and imported it into other projects I've worked on. When exporting this project, I am ONLY exporting the class files that are used for the project. (No system files: ie. Manifest, etc)
I want to leave this project as standalone since it is used in other projects and will be used more in the future.
However, we have other projects that need the features of the network jar and some other features. What I would like to do is create a new project, import the network jar file. Create wrappers for all the functions in the network jar file, then add more functionality.
Afterwards I want to package this project up as a jar file, so that I can use it solely for projects that require that extra functionality.
Having this project as a jar is important, because this component might be given to other people to use, and easy/simple integration is required.
This seamed like it should be pretty straight forward to me. But I am getting noClassDef errors and Verify errors.
I even stripped the project down to a single function that returns a static String from the original network jar and passed that through and still got a "could not find method xxxx referenced from method xxxx" log and then a unable to resolve static method warning, then a No ClassDefFoundError. Here's the logcat.
What is the proper way to do this?
Thanks!
Jar files that want to use embedded jars must define a custom class loader, like JarClassLoader.
If you want to use a single jar file you also have options like OneJar, JarJar, and ProGuard.

How to refer a jar outside exe in Java desktop application?

I have a Java application installed. The jar is bundled into an .exe file using Launch4J. Now I want to create a patch for this application.
If I create another jar containing only updated files, how can I refer it in the original code?
I have java application installed. ..Now I want to create a patch for this application.
This is one of the strengths of the Java Web Start launch technology that comes with the J2SE. Simply update the Jar on the server, and the next time the app. launches, it will be updated.
The update can be honed for your use-case, configured to be done lazily or eagerly, before or after launch, or even programatically controlled using the JNLP API's DownloadService.
..And the jar is bundlled into an .exe file ..
'Unfortunately', JWS works on Windows, ..and Mac., and *nix - so you may have to expand your horizons.
BTW - I have no idea how to do the same with Launch4J, but then, that is really the wrong question. I aim to provide an answer to the right question, which is "How do I deploy & update a Java rich client?". ;)
I've never worked with Launch4J, however I think you should try to affect the classpath. JRE always loads the classes from the classpath. From this point of view, jars have no added value and just serve as a containers for your *.class files and resources.
Now, if you succeed to configure your tool to do something like:
classpath = C:\Temp\my_patch_path;$your_current_classpath
then its enough to put your changed files into C:\Temp\my_patch_path (of course preserving the package structure). JRE will load your classes first in this case.
Hope, this helps
Mark
It is might not be possible to do this without changing the contents of the exe.

Surpress Time Generated Comment when Autogenerating Java Classes from Hibernate

I am using Eclipse and JBoss Tools to generate Java classes from existing Hibernate mappings. Whenever the classes get generated, they have a comment at the top of the class that indicates when the class was auto-generated.
I really want to prevent this from happening since it is a nuisance when these classes are under configuration management. I've looked through all the settings I can think of and online and haven't found out how to do this yet. It seems like it should be very simple, but it hasn't been.
Anyone know how to suppress this comment from being created?
You can edit the tempalte files in the jar file of jboss tools so it does not generate that info. As far as I can remember it uses velocity templates, so you just need to delete that bit from the template files and it wont generate those comments.
When I was using eclipse to generated the POJO's I had the same problem (when working with GIT reporitory). I build a simple program in .Net in order to clean the comments. After I run the hibernate configuration, I run the .exe (it must be located in the same folder of the POJO's files)
You can find the code and an .exe app in https://github.com/jaimeimarin/HibernateHeadersCleaner . If you are working with git remember to add an exception in order to commit the tool.
#Add this line to your .gitignore file
!HibernateHeadersCleaner.exe

Problem running Java .war on Tomcat

I am following the tutorial here:
http://nutch.sourceforge.net/docs/en/tutorial.html
Crawling works fine, as does the test search from the command line.
When I try to fire up tomcat after moving ROOT.war into place(and it unarchiving and creating a new ROOT folder during startup), I get a page with the 500 error and some errors in the Tomcat logs.
HTTP Status 500 - No Context configured to process this request
2009-02-19 15:55:46 WebappLoader[]: Deploy JAR /WEB-INF/lib/xerces-2_6_2.jar to C:\Program Files\Apache Software Foundation\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\xerces-2_6_2.jar
2009-02-19 15:55:47 ContextConfig[] Parse error in default web.xml
org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
at org.apache.commons.digester.Digester.createSAXException(Digester.java:3181)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:3207)
at org.apache.commons.digester.Digester.endElement(Digester.java:1225) ............ etc.
So it looks like the root of the error is default web.xml, not in the Log4JLogger - although I know very little about Java. I did not edit the web.xml in the tomcat dir.
Anyone know what is going on here?
versions/info:
nutch 0.9
Tomcat 4.1
jre1.5.0_08
jdk1.6.0_12
NUTCH_JAVA_HOME=C:\Program Files\Java\jdk1.6.0_12
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_12
In Java, applications sometimes rely on third party libraries. In this case, it appears that your Tomcat installation does not include one such library. Judging by the error you received, it appears that you are missing the Apache Commons Logging library (a commonly used library in the Java world that just so happens to not come bundled with Tomcat).
The typical way to distribute a library in Java is via a JAR (Java Archive) file. Simply put, a JAR file is simply a bunch of Java classes that have been zipped into a file that has been renamed from *.zip to *.jar.
To obtain the Commons Logging JAR file, you can download it from the Apache Commons download site. You will want the binary version, not the source version. Should you happen to download version 1.1.1 (for example), you should unzip the commons-logging-1.1.1-bin.zip file. Inside, you will find a file named commons-logging-1.1.1.jar. Copy this JAR file to the lib directory wherever your Tomcat software is installed. You may be required to restart Tomcat before it notices this new file.
Hopefully, the next time you try to use the application, you may or may not receive yet another error indicating that yet another class cannot be found. In that case, I welcome you to the wonderful world of JAR hunting! :) Hopefully the application will not require too many libraries above and beyond Commons Logging, but we will see (considering you're trying to run Nutch, I can foresee it requiring Lucene, so be prepared for that).
Have fun with Nutch!
For me that tells that it can't find the logger which is reported as a parse error itself. A bit odd or disinformant way to express it, I guess. Anyway, I think you need to add the Commons Logging .jar to your libraries (WEB-INF/lib) and restart Tomcat and then it should work.
Also your Tomcat seems to be ancient, if possible I'd recommend getting 5.5.x or 6.x.
if you found to have required .jar existing in application, than solution to your problem might be to:
Stop Tomcat
go to %TOMCAT_HOME%/work an erase everything inside
this 'work' folder, as its name says, contains classes used for work, sometimes access to some of these files can be blocked for any reason. When I get such message this is first thing to do. Most of the time it works...

Categories