|
Cryolite posted:Is it a good idea to put configuration files in the same directory as my jar files so I can change them without needing to rebuild the jar? Java tools generally look for files on the classpath, using code like getClass().getResourceAsStream("/logback.xml") You set up your classpath when you start the application. Your classpath probably looks something like this: pre:java -cp "a.jar;b.jar;c.jar" entrypoint.jar You can add arbitrary directories to the classpath, and Java will search those too: pre:# add the current directory to the classpath java -cp ".;a.jar;b.jar;c.jar" entrypoint.jar # add the "conf" directory to the classpath and put all our jars in "lib" java -cp "lib/a.jar;lib/b.jar;lib/c.jar;conf" entrypoint.jar java -cp "lib/*;conf" entrypoint.jar It's also common to configure directories with Java system properties or environment variables.
|
# ? Apr 5, 2016 18:12 |
|
|
# ? Jun 13, 2024 05:54 |
|
It's also worth noting that jar files are just zip files with a different extension, so you can open them in any compressed file tool and edit their contents, you don't need to "rebuild" the jar file. But obviously if it's something you expect end users to edit external files are much more convenient.
|
# ? Apr 5, 2016 22:38 |
|
Cryolite posted:Is it a good idea to put configuration files in the same directory as my jar files so I can change them without needing to rebuild the jar? It's not a bad idea - this is how we deploy our services at my company. We've got Chef configured to dump a log4j2.xml and config.json in the same directory as our servicename.jar (standalone web services), and our common service library looks in 1) The current directory, then 2) the classpath for configuration. We use maven as a build tool, so we've got these same files in src/test/resources for our service-level tests, but with different configuration, and these are never compiled into our artifacts. Our philosophy is that, if we don't have the chef-generated configuration correct, we'd rather the service doesn't work at all than have the service work incorrectly by loading configuration that was meant for a different environment. The pattern is probably going to be different if you're not doing SaaS, though.
|
# ? Apr 6, 2016 07:13 |
|
edit: I succeeded close enough
Malloc Voidstar fucked around with this message at 17:52 on Apr 9, 2016 |
# ? Apr 9, 2016 17:03 |
|
Malloc Voidstar posted:edit: I succeeded close enough I was going to say that you have to derive a font and font metrics, and then get the rectangle for the string in the context of your graphics object. code:
|
# ? Apr 10, 2016 02:49 |
|
In the new project I've been assigned to, there's a search function which involves piecing a huge SQL query together in a 600 line function, based on the different search parameters. This seems like a really complicated way of doing it. What's the smart way?
|
# ? Apr 11, 2016 12:33 |
|
Boz0r posted:In the new project I've been assigned to, there's a search function which involves piecing a huge SQL query together in a 600 line function, based on the different search parameters. This seems like a really complicated way of doing it. What's the smart way? I'm going to assume that actually having such a large query is essential to the app's function. The basic idea is to abstract each part of the search out into its own thing. For example, you might write a quick SearchParameter interface: code:
So then you express your queries as a list of SearchParameters, and iterate over those clauses to turn them into SQL whenever you need to actually execute a query. Your "advanced search page" logic might map each text box to the relevant SearchParameter type, while the parser for your regular search box might look for attribute:value pairs in the search query and turn those into SearchParameters of the appropriate type. This decouples everything nicely and makes it easy to update later - if your tables shuffle around a bit, you just need to change the appropriate SearchParameter to filter on the new column, instead of updating the N different places that you actually construct a search query. You can also do cool things like convert a search query into something other than SQL - perhaps you're experimenting with a high-performance or distributed database that doesn't use SQL. Or perhaps you want to display a friendly name to stick in the page title based on what exactly is being searched for. Or maybe you want to turn an arbitrary query back into something the user could type into the text box, so you can teach your users that they can just type "category:foo" into the quick search instead of going to the advanced search every time. Eventually you may want to remix it into the visitor pattern (or some other form of double-dispatch if your language supports it) if you find yourself writing the exact same code for multiple different parameter types, but that's not really necessary to start with.
|
# ? Apr 11, 2016 14:33 |
|
That's exactly the kind of thing I was looking for. Is it called something specific, and do you have some links to examples?
|
# ? Apr 11, 2016 15:24 |
|
Boz0r posted:That's exactly the kind of thing I was looking for. Is it called something specific, and do you have some links to examples? you could do some form of prepared statement
|
# ? Apr 11, 2016 16:22 |
Can anyone recommend some resources for client/server socket programming in Java? I currently have an application designed to retrieve/write data to the database from the client application. I'd like to have the client application communicate with a server and the server will query the database and return results to the client. I've been using this as a resource - https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html. But it's very basic and I'm running into a few issues. How can I have the server always listening for requests and respond by running the appropriate code to query the database, and then return the results to the client? Based on the Oracle example it seems I need to create a protocol. However, the example is just returning one string and I'm confused how to send varying amounts of data between client/server. How does the server know what to expect, when the data has stopped being sent, and assign it to variables? Thanks for any info.
|
|
# ? Apr 11, 2016 16:27 |
|
For a college course I'm writing a paper about Apache Maven. Now, the internet tells me that Gradle is better in almost every way. Okay, that is good to know. But it would be really very useful if I could also write down some advantages of Maven over Gradle (perhaps Maven works better for certain types of projects?) so it seems like I'm doing a fair comparison and then conclude Gradle is the better tool anyway. So, can anyone tell me reasons to use Maven instead of Gradle, and/or link to resources talking about that?
|
# ? Apr 11, 2016 17:18 |
|
Carbon dioxide posted:For a college course I'm writing a paper about Apache Maven. Gradle is faster than Maven, I wish we didnt need to use Maven at work, Our Maven Build has 320 projects and takes 90 minutes to build and test. The same project under Gradle is 312 projects and 15 minutes to build and test. The extra projects in Maven are the bundle poms and the master poms that we have in the master gradle build.gradle as tasks.
|
# ? Apr 11, 2016 18:15 |
|
Carbon dioxide posted:So, can anyone tell me reasons to use Maven instead of Gradle, and/or link to resources talking about that? Some folks might prefer Maven's declaratory XML approach vs. Gradle's interpreted DSL. Usually the DSL is going to be more concise and, often, easier to read. But, if for some reason you wanted to write a third-party tool to parse and do something with your build configurations, it's going to be easier to independently parse an XML-based schema then it is to tie into Groovy and such.
|
# ? Apr 11, 2016 19:14 |
|
Carbon dioxide posted:For a college course I'm writing a paper about Apache Maven. Maven is the industry standard tool, Gradle is some alternative poo poo that Groovy idiots came up with because they're special snowflakes who can't handle XML.
|
# ? Apr 12, 2016 01:25 |
|
TheresaJayne posted:Gradle is faster than Maven, I wish we didnt need to use Maven at work, Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time?
|
# ? Apr 12, 2016 01:44 |
|
JewKiller 3000 posted:Maven is the industry standard tool, Gradle is some alternative poo poo that Groovy idiots came up with because they're special snowflakes who can't handle XML. I'll write my build in a real programming language, thanks. I thought nobody used gradle, but it's almost as popular as maven on github (pom.xml vs build.gradle) smackfu posted:Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time? For one, maven doesn't run in parallel unless you use an experimental flag which is not enabled by default.
|
# ? Apr 12, 2016 02:07 |
|
Ornithology posted:Can anyone recommend some resources for client/server socket programming in Java? I currently have an application designed to retrieve/write data to the database from the client application. I'd like to have the client application communicate with a server and the server will query the database and return results to the client. Do you have a compelling reason to use bare sockets instead of a higher-level abstraction? If you can imagine your client POST-ing a JSON-formatted request to a webserver, and then getting a JSON response back, it might be simpler to leverage Jersey or Spring to set up a server that handles HTTP requests.
|
# ? Apr 12, 2016 04:00 |
|
Dipping my toes in Java right now (using Eclipse if that matters), and my first project is a simple image editor. What I have so far is: I can load an image, rotate it and move it which is nice. But a thought occurred to me to have it so someone could "upload" their own image to my Java application. How would I go about doing this? I tried searching the web before hand but couldn't find anything about uploading/reading new files when the application is already built. Any help is appreciated.
|
# ? Apr 12, 2016 05:21 |
|
smackfu posted:Why would Gradle be faster than Maven? Aren't they both just running other programs (compiler, test runners) which is most of the build / test time? Gradle is a background process, Maven starts up and works from scratch. Gradle should also be better at figuring out which modules have changed, and recompile only the changed parts in subsequent builds. If I remember correctly, then some versions ago the incremental build flag in Maven used to do exactly the opposite of what it was supposed to.
|
# ? Apr 12, 2016 06:43 |
|
Quick question: I am trying to set up Spring Security mappings so that if an authenticated user goes to "/" then they see "/main" but a non-authenticated user would see "/login". I'm using the automatic form-login functionality. I set up a simple controller which does this, but "redirect:/login" as a destination doesn't work, presumably because that's not a real HTML page that exists in the project (it's in the Spring Security JARfile presumably). This seems like pretty basic functionality, there's got to be a way to do this.
|
# ? Apr 13, 2016 19:01 |
|
Gravity Pike posted:Do you have a compelling reason to use bare sockets instead of a higher-level abstraction? If you can imagine your client POST-ing a JSON-formatted request to a webserver, and then getting a JSON response back, it might be simpler to leverage Jersey or Spring to set up a server that handles HTTP requests. Yeah, I don't understand why you'd be re-writing a web server here. Even servlets can be used to send back JSON, just send "text/json" as the content-type and dump a stringified JsonObject into the response body.
|
# ? Apr 13, 2016 19:03 |
|
Nude posted:Dipping my toes in Java right now (using Eclipse if that matters), and my first project is a simple image editor. What I have so far is: I can load an image, rotate it and move it which is nice. But a thought occurred to me to have it so someone could "upload" their own image to my Java application. The simplest way is probably a command-line argument. This lets you pass in a filename/location at the command line like code:
|
# ? Apr 13, 2016 21:46 |
|
Alright if anyone has used JPA/Hibernate before I'm having an issue with a OneToMany bidirectional relationship with a Composite Primary Key In the one class I want a OneToMany relationship with I have this. code:
In the other I have this. code:
Ideally I would prefer to have that security. But as the Database is not being auto generated by hibernate the primary key enforcement doesn't need to happen on this end. (Or is there something wrong with JPA not realizing that 'game' is a part of the primary key?)
|
# ? Apr 14, 2016 16:41 |
|
Nude posted:Dipping my toes in Java right now (using Eclipse if that matters), and my first project is a simple image editor. What I have so far is: I can load an image, rotate it and move it which is nice. But a thought occurred to me to have it so someone could "upload" their own image to my Java application. This is an incredibly broad question. Do you mean simply to "open" the file in your application? "upload" implies a web context. Is your program a java applet or designed to run in a webpage? How are users accessing the program. What is the context? If its simply adding a new image to the program as a desktop app at runtime, there's a few ways to go about it. The common way is to give the user a file browse dialog, let them select the file, and then access the file through disk I/O. Greatbacon posted:The simplest way is probably a command-line argument. This lets you pass in a filename/location at the command line like This is the easiest and fastest way to program, and the upside is that people can drag a picture over the application in order to open the picture in the program. But its also limited, in that they'll have to close and open the program to change pictures. If its a web context, then you have a whole other can of worms to look into, for how to upload the file over the 'net and then how to access that file, but its still perfectly do-able. What exactly are you asking?
|
# ? Apr 14, 2016 16:48 |
|
Cerepol posted:Alright if anyone has used JPA/Hibernate before I'm having an issue with a OneToMany bidirectional relationship with a Composite Primary Key Why do you have two @Id tags? If your primary key is complex, then you probably need the @generatedvalue annotation to tell it how to process the multiple @id tags with a strategy. Does the default handle multiple IDs gracefully?
|
# ? Apr 14, 2016 16:51 |
|
Zaphod42 posted:This is an incredibly broad question. Do you mean simply to "open" the file in your application? "upload" implies a web context. Is your program a java applet or designed to run in a webpage? How are users accessing the program. What is the context? Hey thanks guys for the help, I meant open instead of upload, sorry for being so vague. The problem was mainly I didn't know the key terms to search on google, once I searched Java I/O (which I now know means input/output) I was able to get the docs that I needed to pull this off.
|
# ? Apr 14, 2016 17:04 |
|
Zaphod42 posted:Why do you have two @Id tags? If your primary key is complex, then you probably need the @generatedvalue annotation to tell it how to process the multiple @id tags with a strategy. Does the default handle multiple IDs gracefully? Nah, the @IdClass annotation lets it know what the meaning of their being 2 are. And neither needs to be generated as one is a foreign key and the other will be given by a controller.
|
# ? Apr 14, 2016 17:41 |
|
Cerepol posted:Nah, the @IdClass annotation lets it know what the meaning of their being 2 are. And neither needs to be generated as one is a foreign key and the other will be given by a controller. Hm, well not sure the exact reasoning but with multiple @Id tags not working and removing one working, that's almost assuredly the culprit. Something is confusing the annotations and its not handling it properly.
|
# ? Apr 14, 2016 17:48 |
|
Zaphod42 posted:Hm, well not sure the exact reasoning but with multiple @Id tags not working and removing one working, that's almost assuredly the culprit. Something is confusing the annotations and its not handling it properly. Well I still have 2 @Id tags in the file instead of the 3 where it doesn't work. So as far I as I can tell it's an interaction between a IdClass and the OneToMany reference. Unfortunately it seems rather hard to google and rather rare apparently.
|
# ? Apr 14, 2016 19:13 |
|
How much is typical memory usage for a Spring app? I tried playing around with JHipster, a yeoman generator that generates Spring Boot apps, and so far I've seen memory usage hover around 600MB. Is this normal? It's really slick, but for hosting something on a cheap DigitalOcean box I'm afraid it's a relative memory hog.
|
# ? Apr 16, 2016 00:15 |
|
Cryolite posted:How much is typical memory usage for a Spring app? I tried playing around with JHipster, a yeoman generator that generates Spring Boot apps, and so far I've seen memory usage hover around 600MB. Is this normal? It's really slick, but for hosting something on a cheap DigitalOcean box I'm afraid it's a relative memory hog. What command line is it running? There might be a startup script setting -Xms512m or similar
|
# ? Apr 16, 2016 01:05 |
|
I was running it from Intellij which wasn't setting any of those parameters. When I ran it with -Xmx300m it seemed to obey the max. Interestingly, when I run it from Intellij it pegs one of my CPU cores at 100% even when I'm not doing anything, and the app isn't processing requests that I know of. When I run it using "mvn spring-boot:run" it uses 0% CPU when I'm not doing anything, though the memory usage is still very high - sometimes as high as 800-1000MB.
|
# ? Apr 16, 2016 02:05 |
|
Cryolite posted:How much is typical memory usage for a Spring app? I tried playing around with JHipster, a yeoman generator that generates Spring Boot apps, and so far I've seen memory usage hover around 600MB. Is this normal? It's really slick, but for hosting something on a cheap DigitalOcean box I'm afraid it's a relative memory hog. Our Jersey webapps tend to want around 500MB, yeah.
|
# ? Apr 16, 2016 04:25 |
|
What's the danger of doing -Xmx256m or something like that in this situation then? Way more time spent doing garbage collection?
|
# ? Apr 16, 2016 13:01 |
|
Yeah, I mean, it's Spring Boot, the whole idea is that it should work without config in as many cases as possible. The memory settings were probably chosen fairly arbitrarily but high so that most apps work without getting an out-of-memory error.
|
# ? Apr 16, 2016 14:31 |
|
Cryolite posted:What's the danger of doing -Xmx256m or something like that in this situation then? Way more time spent doing garbage collection? If you want to see all the information you can handle about what your application's doing with memory, there's a visual memory/cpu profiler that comes with the JDK: jvisualvm.exe Sindai fucked around with this message at 18:02 on Apr 18, 2016 |
# ? Apr 18, 2016 17:56 |
|
Cerepol posted:Alright if anyone has used JPA/Hibernate before I'm having an issue with a OneToMany bidirectional relationship with a Composite Primary Key Did you try using an EmbeddedId? I've done something like this before which looks similar to your use case: code:
|
# ? Apr 19, 2016 22:13 |
|
Once again I'm fighting with loving logging and loving log levels, this time with jetty. (mvn jetty:run) How the gently caress do I make it so that my call to LOG.debug("loving Christ I'm tired of this poo poo"); actually gets logged. Info, warn, error and fatal levels work fine. edit: LOG is an instange of org.apache.commons.logging.Log Wheany fucked around with this message at 08:37 on Apr 21, 2016 |
# ? Apr 21, 2016 08:33 |
|
Usually there is some sort of configuration file depending on the underlying log implementation where you have to set the root level to DEBUG and not INFO where its at now.
|
# ? Apr 21, 2016 11:58 |
|
|
# ? Jun 13, 2024 05:54 |
|
I haven't used commons-logging but it looks like the same design as log4j, like FateFree said there's just a config file somewhere you need to modify. Its useful because it lets you set lots of custom error levels, so you could get full DEBUG level from mydomain.* classes, but then set it to ERROR level only for org.apache.* classes or whatever. Its very useful for quickly fine-tuning your logging messages, but can be a pain to get set up at first if you're not seeing the message you want. If you're seeing error messages but not debug, its gotta just be the config.
|
# ? Apr 21, 2016 15:57 |