PluralSight custom playback speeds
Learn even faster by watching videos at faster than 2x playback speed.
Learn even faster by watching videos at faster than 2x playback speed.
Warning: this post could probably be countered with a simple RTFM! But for those who are Googling for this, I hope it helps.
Today I tested out how our Xtend 2.8 code that works in Java 7 would go in a Java 8 JDK. For the most part it was ok but one problem that we experienced was related to sorting collections.
We had code like:
val someCustomerComparator = ... // a java.util.Comparator
for(item : someEObject.items.sort(someCustomComparator)) {
// do stuff
}
The sort method here is:
I’m working with Apache Jena and Apache Fuseki (v2.3.1) at the moment and today I had the need to load more than one lot of data into Fuseki on start up. I thought I needed an assembler file, and I probably could’ve used one, but I’ve ended up using config file for Fuseki.
I was Googling for ’example Fuseki config files’ to get up and running quickly but didn’t find anything so it’s my hope that others can use this blog post to get a TDB data directory loaded into Fuseki using a config file quickly.
I wrote some code that required an XMLGregorianCalendar so when I poked around with code completion, the first thing I found was a constructor on com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl
. This got my code working but when you build with Maven, you get given a warning (and rightly so):
XMLGregorianCalendarImpl is internal proprietary API and may be removed in a future release
The correct way to get something that conforms to the XMLGregorianCalendar interface is to call this factory:
We developed a Spring MVC controller that needs to know who the client is. We achieved this using a HttpServletRequest
parameter and then calling getRemoteAddr()
on it. The challenge then was how to test this because we need to be able to mock this value.
The Spring test helpers don’t provide a way to set this value with a helper method but they do provide an extension point that we can use to do it ourselves. The extension point is the .with(RequestPostProcessor)
method:
You’re trying to build an Eclipse update site project, specifically <packaging>eclipse-repository</packaging>
, with maven and you’re getting the following error:
[INFO] --- tycho-p2-director-plugin:0.21.0:archive-products (default) @ YourProject.UpdateSite ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:00.627s
[INFO] Finished at: Mon Oct 27 09:56:51 CST 2014
[INFO] Final Memory: 84M/764M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-director-plugin:0.21.0:archive-products (default) on project YourProject.UpdateSite: Error packing product: /path/to/YourProject.UpdateSite/target/products/your.product/linux/gtk/x86 isn't a directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
This error message is specific to this environment block that you would have defined in your POM:
I found this problem when I was trying to bundle a maven project as an OSGi bundle to use with Tycho. The bundle I was trying to make was effectively a shaded/uber JAR that has all the dependencies inlined inside of the final artifact JAR.
This problem is caused by a Java class file existing in the default/unamed package. It could come from anywhere in the dependency chain, including your own project, but in this case it came from one of my dependencies; JDOM.
Problem
The Xtext project I’m working with had, what I assume is, the default project structure where all the java source code lives in a src directory and the generated code goes into src-gen. I wanted to change the structure to a more maven-like structure and have the java code living under src/main/java. I wasn’t too fussed about the src-gen directory, that can stay where it is. I Googled for a while but I couldn’t find anyone asking the same question as me so hopefully this will help any others (and my future self).
Note: I’m working in Eclipse with Spring 3 and using jUnit for my tests.
Background
I was writing a unit test for a file upload method on a controller that looks like:
mockMvc.perform(fileUpload("/fileUpload")
.param("description", "blah")
)
.andExpect(status().isOk());
The test was failing with the message:
java.lang.AssertionError: Status expected:<200> but was:<400>
This isn’t super helpful because I wasn’t sure why I was getting the 400. I tried changing the URL that I was testing and the error code changed to a 404 so I knew the request was trying to get to the right controller method. I also put a breakpoint in my controller method but it was never hit so I knew it was the configuration of the test and not the code in the controller method that was causing the issue.
Note: this was done on a rooted Android. It may work on Apple devices but you definitely require root on Android.
Background
I’ve become a bit addicted to this game and in the course of playing it, I’ve had it rip me off a few times. This happened when I’d open the game after, it’d been sitting for a while, but then it would crash a few seconds after and when I relaunched it, the extra money I’d earned wouldn’t be there.
As some background, I’m running the following:
The specific error that we’re going to fix is:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public au.com.your.package.YourResponse au.com.your.package.YourClass.someMethod(au.com.your.package.YourRequest) at parameter at index 0
SEVERE: Method, public au.com.your.package.YourResponse au.com.your.package.YourClass.someMethod(au.com.your.package.YourRequest), annotated with GET of resource, class au.com.your.package.YourClass, is not recognized as valid resource method.
If you’re running Tomcat like I am then you’ll see this in your catalina.out
log file.
I came across this problem the other day and thought I’d post up the fix because it’s simple to fix but a show stopper if you can’t.
I’m running Linux Mint 64-bit Cinnamon and Postgres 9.1 as a refenece in case you can’t copy-paste my commands.
Basically, when I copied an already running version of postgres to a new box and it failed to start. When I took a look in the postgres log for when you try to start it, I could see that it was complaining about a missing locale. For me, it was en_AU.UTF-8
.
How to ssh-add
on a remote machine.
When you generate a Java project using maven and then import it into Eclipse, often you want to add extra directories that are treated as source directories. This guide will show you how to do it.
First lets look at (a snippet of) the Super POM to see what we get by default:
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
We can override what we get from here which is probably what you’ll do most of the time; adding another resource directory. When you add another resource remember that you’re overriding the default so if you still want src/main/resources
then you’ll have to explicitly add it.