Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
CPColin
Sep 9, 2003

Big ol' smile.
Yeah, you shouldn't ever compare Strings using ==. Always use String.equals() or you'll get behavior like you're seeing.

Adbot
ADBOT LOVES YOU

Trick Question
Apr 9, 2007


Yep, that fixed it instantly. Thanks for the help!

Boz0r
Sep 7, 2006
The Rocketship in action.
What's the correct way to include .jar libraries in deploys for JBoss? I've done it a couple of different ways. Thrown it into JBoss' lib folder, in the project's lib folder, in the MANIFEST.MF file, in the ant build file.

smackfu
Jun 7, 2004

Use Maven and don't think about it?

BabyFur Denny
Mar 18, 2003
if it's not in some maven repository, don't use it.

geeves
Sep 16, 2004

BabyFur Denny posted:

if it's not in some maven repository, don't use it.

I don't agree with this at all. There are some libraries that are hosted in Maven Central that have, for lack of better term, "add-on" libraries that are not in Maven Central that you have to download individually (Why IBM? Why?) or you might have a very old library that still has a need in your application and you can't find a suitable replacement or just can't do a refactor at the moment.

So instead, use Artifactory and upload it to your own Maven repository.

Ariong
Jun 25, 2012

Get bashed, platonist!

I'm new to Java and I'm having a problem that nobody else seems to have, or at least, not that google can find. See, when using String.format, if you want to print a literal % in your string, you escape it with another %. So, if you wanted to print a formatted string that looks like this:

quote:

This is a percent sign: %

You would write this code:
code:
System.out.printf("This is a percent sign: %%");
That's all well and good. However, it doesn't seem to work with strings that are passed by methods. For example, when I run this program:

code:
System.out.printf(getFormattedString.getString());
Which references this method within the getFormattedString class:

code:
public static String getString()
    {
        String str = String.format("Here is a percent sign: %%");
        
        return str;
    }
I get an exception, just as though I didn't use an escape character. What gives? If this is not the correct thread/subforum for this question, please let me know.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
System.out.printf is special, it has the formatting stuff built in, so you're probably end up doing it twice. Try playing around with System.out.println instead.

smackfu
Jun 7, 2004

Aren't you essentially calling format twice?

efb

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Yeah the f is for format (or formatted or whatever). You're basically stripping out the escape % with the first format call

Ariong
Jun 25, 2012

Get bashed, platonist!

Ah! That makes sense. Thanks so much, that's been bugging me for weeks.

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

geeves posted:

I don't agree with this at all. There are some libraries that are hosted in Maven Central that have, for lack of better term, "add-on" libraries that are not in Maven Central that you have to download individually (Why IBM? Why?) or you might have a very old library that still has a need in your application and you can't find a suitable replacement or just can't do a refactor at the moment.

So instead, use Artifactory and upload it to your own Maven repository.

Yup. Pretty much any artifact that is under one of Sun's packages, or javax.*, and is NOT an API-only jar, is not going to be available in the Maven-Central repo. Sun/Oracle's license is pretty horrendous and so they get shut out of OSS repositories. Same problem that afflicts Oracle JDK in the official distributions.

The place where this usually bites you is stuff like the Oracle OJDBC driver, or some of the javax artifacts like jdbc-stdext. For the most part, web stuff will be bundled and/or injected with your web server so at least that's not a real problem - you just need to note it as "provided" in your pom.xml.

In theory you should be able to point Maven at a "local repository" across file:// too - however I haven't been able to make this work reliably. It works for my local PC (probably gets installed into my .m2) but not on other computers. Also, Maven's caching rules are a cast-iron bitch for trying to debug this and I haven't figured out a viable way around them short of deleting the whole .m2 folder and letting it re-resolve everything.

Gradle, on the other hand, works perfectly in this use-case. It understands the concept of a Maven repository on disk, or you can just give it a "libs" directory full of jars to include like you would with an Ant build. As such I think that probably makes it an easier sell for teams converting from legacy Ant build scripts and/or working offline.

This is kind of unfortunate since in theory I like the idea of a Maven build much better. The declarative model is very easy for IDEs to handle for setting up classpath, and unlike Gradle you don't need a "build daemon" hanging around to get decent performance. But apart from the "imperative" style format and the daemon - I think they really get you to pretty much the same place. And gradle gives you a better mix for transitioning legacy code - you can write pretty much the same stuff as you would in Ant, but you benefit from the dependency resolution and modern conventions of Maven.

smackfu
Jun 7, 2004

Your legal department probably doesn't want you to use that weird Sun junk anyways.

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

smackfu posted:

Your legal department probably doesn't want you to use that weird Sun junk anyways.

I personally stay the hell away from it, if for no other reason than because since it's not in the main repos it doesn't get automatic updates.

Still though, you might be surprised. The ToS from Oracle are a known quantity, and lots of project managers prefer the devil you know over "software from some guy on the internet" and "regular security updates" and similar forms of heresy.

Again, given that the client is using Oracle DB anyway, we're kind of in for a penny anyway, but at least that's mostly on them, they made that deal with the devil themselves.

Personally I'd go with Postgres over literally anything else any day, unless my workload literally couldn't be serviced by a decked-out 8-socket Xeon server. So far it doesn't have good support for horizontal scaling/distributed transactions - but anything short of that it works fine.

Honestly OJDBC has been one parade of bugs after another. Today, Hibernate decided to revert to the default sequence for no actual reason that we can determine - but only on the "sequence" generator type, the deprecated "sequence-identity" generator type works fine.

Paul MaudDib fucked around with this message at 03:47 on Mar 15, 2017

BabyFur Denny
Mar 18, 2003

geeves posted:

I don't agree with this at all. There are some libraries that are hosted in Maven Central that have, for lack of better term, "add-on" libraries that are not in Maven Central that you have to download individually (Why IBM? Why?) or you might have a very old library that still has a need in your application and you can't find a suitable replacement or just can't do a refactor at the moment.

So instead, use Artifactory and upload it to your own Maven repository.

If it is in your artifactory then it is in a maven repository and it's fine. So we actually don't disagree.

geeves
Sep 16, 2004

BabyFur Denny posted:

If it is in your artifactory then it is in a maven repository and it's fine. So we actually don't disagree.

True :haw:

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
I'm using a few libraries which depend on different versions of Guava. A few use an older version of Guava and when I try to do something with the jar I'm building (Spark-submit it) it's giving me a NoSuchMethod error. That method is missing in Guava before 15. I assume that the class loader is loading an older version for some reason, even though Gradle's dependency tree shows everything being forced to the latest version.

Is there a way for me to handle this? I did something similar with shading but I can't see to figure this out.

hooah
Feb 6, 2006
WTF?
I'd like to start up a personal project to learn more about the Java EE world, but I've never been good at coming up with something myself. I thought about making a web service that will tell you if Netflix has a given title and then possibly expanding that to include an Android app which would let you use the Google Assistant, but it looks like Netflix ended that API some time ago, so that might not be feasible. Where can I go to get ideas for this sort of project?

geeves
Sep 16, 2004

Good Will Hrunting posted:

I'm using a few libraries which depend on different versions of Guava. A few use an older version of Guava and when I try to do something with the jar I'm building (Spark-submit it) it's giving me a NoSuchMethod error. That method is missing in Guava before 15. I assume that the class loader is loading an older version for some reason, even though Gradle's dependency tree shows everything being forced to the latest version.

Is there a way for me to handle this? I did something similar with shading but I can't see to figure this out.

Have you excluded the dependencies from the library that might be responsible in your gradle.build file? (I just went through this process with Maven, it's a pain in the rear end.)

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

geeves posted:

Have you excluded the dependencies from the library that might be responsible in your gradle.build file? (I just went through this process with Maven, it's a pain in the rear end.)

Our last resort is excluding all pre-14 (or 15) Guava transitive dependencies from all of the dependencies that pull it in and just leave the ones with post-problematic Guava. I'm not sure how Gradle works but I assume that it won't even download them or add them to the classpath if I do this exclusion, right?

(Disclaimer: This is my first job using Gradle and I've used it for 2 weeks, before that I used Maven)

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

Good Will Hrunting posted:

I'm using a few libraries which depend on different versions of Guava. A few use an older version of Guava and when I try to do something with the jar I'm building (Spark-submit it) it's giving me a NoSuchMethod error. That method is missing in Guava before 15. I assume that the class loader is loading an older version for some reason, even though Gradle's dependency tree shows everything being forced to the latest version.

Is there a way for me to handle this? I did something similar with shading but I can't see to figure this out.

This is not gradle-specific, and it's pretty much always one of two problems. You either have an API jar and no implementation, or you have two copies of this hanging out somewhere in your dependencies. Look again.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Paul MaudDib posted:

two copies of this hanging out somewhere in your dependencies

What do you mean by this? The problematic Guava version is being provided somewhere other than dependency resolution?

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

Good Will Hrunting posted:

What do you mean by this? The problematic Guava version is being provided somewhere other than dependency resolution?

Maybe not that version, but you have two versions coming from somewhere. Maybe try building a jar-with-dependencies and see if there's two copies in there? Maybe there's another copy in a far-jar that is outside dependency resolution?

smackfu
Jun 7, 2004

Ask, the libraries that rely on older versions of the dependencies might not even work properly with the new one, even if you get it set to only use the new one. So that's fun.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Paul MaudDib posted:

Maybe not that version, but you have two versions coming from somewhere. Maybe try building a jar-with-dependencies and see if there's two copies in there? Maybe there's another copy in a far-jar that is outside dependency resolution?

So I built the jar with dependencies - am I looking for multiple copies of the class in the results of jar tf?

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
Found it by adding -verbose:class to spark-submit to show where the classes were being loaded from. Inside the Spark download there's a jars director with an old version of Guava.

Tactical Shitpost
Jun 13, 2016
When working with tasks that query external services (and thus block the thread on a thread pool/executor service), do you guys use anything to provide Green Threads or similar functionality? Anything that doesn't require using JVM agents, like Quasar does?

I'm dealing with something where a single request can issue multiple tasks which are submitted to an executor service, where each task has to query an external service (with some timeout) blocking the thread. I'm kinda paranoid that the slowdown on the external service would exhaust the parent thread pool, so i'm looking for better alternatives.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Take a look at Dagger Producers, and see if that sounds promising for you.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
What's the best way to avoid dependency conflicts when dealing with libraries that are only offered via fat JAR? Spark just ships with so many old dependencies that are giving me a massive headache when trying to work with multiple other necessary libraries.

Sedro
Dec 31, 2008

Good Will Hrunting posted:

What's the best way to avoid dependency conflicts when dealing with libraries that are only offered via fat JAR? Spark just ships with so many old dependencies that are giving me a massive headache when trying to work with multiple other necessary libraries.

Spark is in Maven Central un-bundled, unless that's a different artifact?

In general the solutions to this problem are shading (rewrite bytecode so your conflicting dependencies have unique package names) or OSGi (run each dependency in its own classloader).

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Sedro posted:

Spark is in Maven Central un-bundled, unless that's a different artifact?

In general the solutions to this problem are shading (rewrite bytecode so your conflicting dependencies have unique package names) or OSGi (run each dependency in its own classloader).

To submit Spark apps (at least via spark-submit which I'm trying to use right now) you have to package all of your necessary JARs (including all dependencies of Spark) together in a fat JAR for submission so I don't think the un-bundled version will help too much unfortunately.

The issue I'm having is that my app needs, for example, library A version 2.0 which depends on library B version 2.0 whereas Spark's bundle comes with and depends on library B version 1.5. Cross-versioning is causing issues on both sides, both older and newer. I need to look into shading to see if this is a problem that can be solved by it but I'm not sure how it would work with the transitive dependencies.

Sedro
Dec 31, 2008
If you're building the fat jar yourself with maven-assembly-plugin or similar, it should include version 2.0 and not version 1.5. Things get nasty though if the two versions are not compatible.

BabyFur Denny
Mar 18, 2003
One of the many reasons why spark is such a terribly lovely framework

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

BabyFur Denny posted:

One of the many reasons why spark is such a terribly lovely framework

This is the first I've used it outside of Databricks managed service for processing 200,000,000 line flat files from third party data sources and batch writing them to a database, which it ruled for doing easily. Doing this poo poo sucks so far.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Best book, or way to learn Java for someone who hasn't touched it since applets and Java 2?

geeves
Sep 16, 2004

Bob Morales posted:

Best book, or way to learn Java for someone who hasn't touched it since applets and Java 2?

Effective Java

Java 8 Lambdas Functional Programming for the Masses


Edit: correct title.

geeves fucked around with this message at 00:43 on Mar 21, 2017

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
On that same line of thinking, does anyone have a course or program they could recommend for learning web services? I really need to bite the bullet and get my head around it to get some reporting tools on our intranet. I had a coworker make a mockup Spring example for me but I really learn by doing so a class over just a book or site would be preferred.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
What do you mean web services? That's pretty broad! What are you trying to do?

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Good Will Hrunting posted:

What do you mean web services? That's pretty broad! What are you trying to do?

Ultimately I'd like to publish reports from a tool with an API to a site so users can query for live results. I have a basic Swing GUI with all the proper reports and results, but they want a web interface instead of an executable. I don't particularly mind as I'd like to learn this angle of things anyway.

The reports are just plaintext information, so the data in question is simple, I just need to publish it with a method to query based on string search values.

Adbot
ADBOT LOVES YOU

geeves
Sep 16, 2004

PierreTheMime posted:

Ultimately I'd like to publish reports from a tool with an API to a site so users can query for live results. I have a basic Swing GUI with all the proper reports and results, but they want a web interface instead of an executable. I don't particularly mind as I'd like to learn this angle of things anyway.

The reports are just plaintext information, so the data in question is simple, I just need to publish it with a method to query based on string search values.

Look into Jersey https://jersey.java.net or Spring Boot with REST https://spring.io/guides/gs/rest-service/ (We use the former in production and for a brand new API looking into the latter.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply