|
PlesantDilemma posted:Newbie here. I'm using Maven and NetBeans 7.4. How do I get maven to copy some xml & properties files from src to target when I run `mvn package`? The files are in src/main/java/com/mycompany/reports/config. When I run the jar it keeps dying saying it cant find the files in target/classes/com/mycompany/reports/config. I've been surfing the maven site for a while but I'm not seeing what I need to put in my pom to get it to copy the files. In maven, your config files should be under src/main/resources. Only java files should be under /src/main/java. By default anything under src/main/resources will get copied into the resulting jar / war / ear.
|
# ? May 23, 2014 19:39 |
|
|
# ? May 27, 2024 16:44 |
|
Good lord JSF is an abortion. Someone please kill me.
|
# ? May 26, 2014 16:12 |
|
Can anyone recommend something similar to CodingBat for online, interactive Java problems? I like CodingBat a lot, but it doesn't cover a wide spread of the language. I have an exam next week and I find I tend to remember concepts more easily when I've actually coded something with them.
|
# ? May 27, 2014 10:40 |
|
I'm getting into a new project, currently in requirements/design phase. I've decided to go with Java for a number of reasons, but it's been quite a while since I've used it in any serious effort. I'm planning to use the latest Eclipse (Kepler), but I wanted to know what you thought of using NetBeans instead? I'm relatively familiar with Eclipse but I hear great things about NetBeans. Also, what's are the standard options for good MVC frameworks (or other design architectures) and testing suites? I'm afraid that I haven't used either in my previous projects, but this one I want to do the right way. Naturally my first thought was to ask here.
|
# ? May 27, 2014 16:20 |
|
Netbeans has a nice interface for managing various extensions such as you might want to use in testing, etc. I'm not sure about Eclipse, but I seem to recall that it's less intuitive in that respect. But I'm a pleb, so Netbeans saddens me by its clunkiness in formatting: it doesn't newline things automatically if a string gets too long; if I put a newline before the closing ) in a method it won't do anything about it; it doesn't sort members; its "Insert code" refactor-like tool always goes to the very front... But I just like form building too much. I actually came here to ask: code:
|
# ? May 27, 2014 17:14 |
|
Isn't "extends Object" kind of redundant? The reason to put "extends" or "implements" into a a generic bracket is to restrict usage of the class/method to types inheriting from a class or using an interface. E.g.: If you wanted to use .compare() inside your method you could define the generic as <T implements Comparable> to make sure only classes using that interface are allowed. Also you don't appear to be using the parameter 'c' anywhere. Java code:
What kind of compilation error are you getting?
|
# ? May 27, 2014 19:16 |
|
Hmmm. Are you sure? I hoped that via my redundant Class<T> c it was getting a hint at what class it was supposed to load. Basically, will the object input stream care what class the object is? Oh, if I write ExerciseManager exerciseManager = DataLoader.loadObject(exerciseManagerPath, WindowPreferences.class); it says, "incompatible types: inference variable T has incompatible bounds equality constraints: logic.WindowPreferences upper bounds: logic.ExerciseManager,java.lang.Object where T is a type-variable: T extends Object declared in method <T>loadObject(String.Class<T>) The type of <T>loadObject(String, Class<T>) is erroneous where T is a type-variable: T extends Object declared in method <T>loadObject(String.Class<T>)" Carefully copied from the Netbeans hint for completeness. I actually don't know what any of that means. Also, I guess I know very little about generic types.
|
# ? May 27, 2014 19:47 |
|
ObjectInputStream should always return an object of type Object. It shouldn't ever have any idea what type T is; you're just casting it after the fact. What's the relationship between WindowPreferences and ExerciseManager? It looks to me like you're getting an error because calling "exerciseManager = DataLoader.loadObject()" infers that T is of type ExerciseManager, but you're passing "WindowsPreferences.class" as the second parameter and implying a different type. What happens if you use "ExerciseManager.class" as the second parameter, or just remove the second parameter and call: Java code:
|
# ? May 27, 2014 20:19 |
|
WindowPreferences and ExerciseManager are totally unrelated, and if I pass ExerciseManager.class it works just fine. Also,Fellatio del Toro posted:ObjectInputStream should always return an object of type Object. It shouldn't ever have any idea what type T is; you're just casting it after the fact. Aaand, it works without the second parameter. I just wanted to follow the example of famous methods that I can't recall right now, but which pass a class as a parameter and get magic. I don't think they work with files, though.
|
# ? May 27, 2014 20:37 |
|
The compiler should be able to infer the type of T by what you're assigning the returned value to. I think the purpose of the second parameter is to let you explicitly define the type in the event that the inference is not necessarily sufficient. I'm struggling to come up with a good example though. If you were using a void method you'd need the second parameter. Or if you wanted to load a subclass from a file but store it as its superclass you could use the second parameter to make sure it gets loaded as the correct type.
|
# ? May 27, 2014 20:53 |
|
PlesantDilemma posted:Newbie here. I'm using Maven and NetBeans 7.4. How do I get maven to copy some xml & properties files from src to target when I run `mvn package`? The files are in src/main/java/com/mycompany/reports/config. When I run the jar it keeps dying saying it cant find the files in target/classes/com/mycompany/reports/config. I've been surfing the maven site for a while but I'm not seeing what I need to put in my pom to get it to copy the files. Don't you need to put them in the src/main/resources/... folder?
|
# ? May 29, 2014 11:18 |
|
Fellatio del Toro posted:The compiler should be able to infer the type of T by what you're assigning the returned value to. I think the purpose of the second parameter is to let you explicitly define the type in the event that the inference is not necessarily sufficient. I'm struggling to come up with a good example though. Your second option is correct. The second parameter is for type constraint. I hate you people that get to use fancy Java 1.8 or even 1.7.
|
# ? May 29, 2014 15:19 |
|
TheresaJayne posted:Don't you need to put them in the src/main/resources/... folder? Yeah, that is the correct place for them. However, after chatting about it we decided that the config files shouldn't live in the jar anyway. But thanks for the help, thread. Maven is a deep program, lots of stuff to tweak, configure, and learn.
|
# ? May 29, 2014 19:23 |
|
You can use the maven resources plugin to exclude resources from the jar and put them elsewhere as part of the build process, though the documentation is fairly cryptic. It's also worth looking at the maven assembly plugin which handles build packaging and the like if you haven't already.
|
# ? May 29, 2014 20:03 |
|
Ookay, I just discovered on Windows that Java 8 is still some kind of "for hackers" version, because java.com recommends 7.60. I mean, sure, I can find a Java 8 download on the site, but so I'll have to again if I want to run my program on a different computer. Any ETA on 8's official acceptance?
|
# ? May 31, 2014 06:16 |
|
I'm not sure why java.com isn't pushing Java 8. As far as I know the release date was back in March. I mean, you'll always have to deal with needing your users to use the version of Java you target, and it's difficult to say when 8 will reach mainstream/majority share, but the version of Java 8 you can download is the one intended for general use, if that's what you're asking.
|
# ? May 31, 2014 06:37 |
|
As far as I'm concerned, I'm the only user of my programs, and it turns out, Java 8 download isn't that hard to find. Although the place I might test my programs on a different computer might lack an Internet connection altogether, so maybe I'll carry an installer on a USB drive just in case.
|
# ? May 31, 2014 07:06 |
|
When will Java finally gain const-correctness? Or is there some fundamental reason why Oracle would never develop such a feature?
|
# ? Jun 1, 2014 22:08 |
|
pr0metheus posted:When will Java finally gain const-correctness? Or is there some fundamental reason why Oracle would never develop such a feature? What would you expect from such a feature that you don't already have in the language? final is not good enough for you? immutable is not ok?
|
# ? Jun 1, 2014 22:36 |
|
pr0metheus posted:When will Java finally gain const-correctness? Or is there some fundamental reason why Oracle would never develop such a feature? Since the language didn't start with const, you can't introduce const without adding an escape hatch. When you add the ability to cast away const, you've weakened the guarantee of const to the point where it's pretty much just an declaration of intent.
|
# ? Jun 1, 2014 22:44 |
|
Is it possible to create a balance k-d tree that contains all possible RGB values. All the algorithms I try either take way too long or run out of memory.
|
# ? Jun 3, 2014 22:47 |
|
RGB being 0..255? That's 255^3 leaves, so 2 * 255^3 - 1 nodes, or about 33 million nodes. Assuming about 32 bytes per node, you'd need about a gig of memory to store this. I actually have no clue how large these nodes would be in memory - I could be off by quite a bit, so an OOM error sounds reasonable. What are you actually trying to do here?
|
# ? Jun 3, 2014 23:04 |
|
Gravity Pike posted:RGB being 0..255? That's 255^3 leaves, so 2 * 255^3 - 1 nodes, or about 33 million nodes. Assuming about 32 bytes per node, you'd need about a gig of memory to store this. I actually have no clue how large these nodes would be in memory - I could be off by quite a bit, so an OOM error sounds reasonable. why would it not be 256^3 = ~17 million nodes? I want to make an image 4096x4096 that uses all colors exactly once. I wanted to use k-d tree to search nearest neighbors quicly.
|
# ? Jun 4, 2014 01:19 |
|
Fedaykin posted:why would it not be 256^3 = ~17 million nodes? Try it with arrays first. A k-d tree is super overkill for this. This can be easily done with a couple arrays and a bitmask. One array can hold all the colors (~16 MB), another can hold all the neighbors of set pixels (initially empty, worst case < 64MB), and the bitmask will be true at an index if the corresponding pixel is set and false otherwise (~2 MB). Shuffle the colors or whatever first. Then choose a random pixel, and set it to the first color. Set that pixel's bit to true, and add its neighbors to the array of available neighbors. Then iterate over the remaining colors, choose the pixel from the array whose neighbors are closest to that color, and set it to the color. Update the bitmask, rinse and repeat. Should take less than 100 MB of memory in all, no need for a K-D tree. Here's two animations with different ways of calculating the nearest neighbor (APNG format): Here's one end product:
|
# ? Jun 4, 2014 01:44 |
|
Fedaykin posted:why would it not be 256^3 = ~17 million nodes? Er, crap nodes have values in a k-d tree, don't they? That's the whole danged point. You're correct, it's 17 million.
|
# ? Jun 4, 2014 04:25 |
|
quote:Then iterate over the remaining colors, choose the pixel from the array whose neighbors are closest to that color, and set it to the color. Update the bitmask, rinse and repeat. Iterating over 17 million possible colors for 17 million pixels would take a very long time. http://joco.name/2014/03/02/all-rgb-colors-in-one-image/ According to this that would take around 50+ hours. If you used a tree instead it would only take log2(256^3) ~ 24 iterations through the tree for each pixel instead of 17 million edit: http://en.wikipedia.org/wiki/K-d_tree#Nearest_neighbour_search Fedaykin fucked around with this message at 21:29 on Jun 4, 2014 |
# ? Jun 4, 2014 21:13 |
|
Even better if you're willing to tolerate sometimes not getting the actual nearest neighbour: http://www.cs.ubc.ca/research/flann/
|
# ? Jun 4, 2014 22:50 |
|
Fedaykin posted:Iterating over 17 million possible colors for 17 million pixels would take a very long time. We know what a k-d tree is. What I described is roughly the algorithm used in that article. If I understand you right, you want to place set pixels in a k-d tree based on their color so you can more quickly look up the closest pixel to the current color, right? My back of the envelope calculations suggest that'd take ~128 MB for an array of values. Add in the overhead of Java objects, the tree and bookkeeping, and I'd figure this is possible in under a gigabyte, plus ~100 MB for the image itself. Without seeing what you've done, it's hard to say why you're running out of memory.
|
# ? Jun 5, 2014 04:19 |
|
I have a legacy database that stores a customer object as a giant xml blob. This won't change any time soon. I need to build an indexing solution so that we can search for customers by some of its nested attributes. Would lucene be the most obvious choice? Or maybe an in-memory database of some kind that can keep its index in memory? I think we are dealing with about 20 million customers or so, so it would need to scale. Also, the indexer only needs to return customer ids which we would then query the database for. Any ideas?
|
# ? Jun 10, 2014 12:54 |
|
Add new columns to the database and write a script that extracts the data you need from the xml and uses it to populate the new columns. Then add a trigger so any updates to the database get added to the new column as well. The new column won't interfere with your existing functionality and it will allow you to add true indexing. You'll still have a lovely database architecture but you'll hate working with it a lot less.
|
# ? Jun 10, 2014 13:32 |
|
FateFree posted:I have a legacy database that stores a customer object as a giant xml blob. This won't change any time soon. I need to build an indexing solution so that we can search for customers by some of its nested attributes. Would lucene be the most obvious choice? Or maybe an in-memory database of some kind that can keep its index in memory? Why not go with a NoSQL db? Mongo? Redis? Or some other document storage solution, out of the bazillions available? Or, since you have to add code to store the customer object in whatever solution you will adopt (in addition to the blob in the database), you could put it in new database tables as well, and use the database indexing to search for it. If it fits in a relational database that is.
|
# ? Jun 10, 2014 13:36 |
|
Ok, I should have mentioned that our current solution IS another table in the same database with name/value/pk indexes. But its too slow. The database is crap and cannot be changed, nor can data be moved off of it, so we're looking for an entirely separate solution to live alongside it.
|
# ? Jun 10, 2014 14:58 |
|
FateFree posted:I have a legacy database that stores a customer object as a giant xml blob. This won't change any time soon. I need to build an indexing solution so that we can search for customers by some of its nested attributes. Would lucene be the most obvious choice? Or maybe an in-memory database of some kind that can keep its index in memory? Lucene should work great. Searching giant (xml) blobs by attributes and/or full text is what it does best. Take a look at Apache Solr or Elasticsearch for a standalone, manageable solution that help with importing the data and keeping it in sync, too. Some companies use a Lucene or similar index as a reverse proxy to customer data even when it's all neatly normalized, because with tens of millions of clients and billions of (seldom changing) records it'd still be a bitch to gather it all quickly. pigdog fucked around with this message at 15:41 on Jun 10, 2014 |
# ? Jun 10, 2014 15:38 |
|
I have a problem and I can't figure out if it is a Java or MySQL problem. I connect to a MySQL database and get a bunch of rows and process them. I noticed that sometimes my results were different than what I expected. So I set up my app to always process the same rows and write down the results. Testing this, I ran it in batches of 20. Sometimes 4 or 8 of the 20 runs would have different results, even through all 20 were bringing in the same data. Then I had it print out the data it was getting from the database. On some runs, a MySQL DATETIME column will return the wrong date. It is always off by 8 hours. I look at what is in the database and it is different from what Java pulled out. I do not understand how this can be. I expect this to be a timezone related problem, but I can not figure out how. The tricky thing is that it does not always happen. I can not predict or reproduce the error at will. But if I set it up to run a bunch of times, I always see a few runs get out bad data. I'm not a Java expert, what kind of steps can I take to diagnose the problem? I also query this data in a PHP script and the PHP side has never had this issue. Very frustrating.
|
# ? Jun 11, 2014 20:14 |
|
PlesantDilemma posted:I have a problem and I can't figure out if it is a Java or MySQL problem. What timezone does your computer run in? What timezone do your service servers run in (if applicable)? What timezone does the MySQL server run in? What timezone do you expect dates to be stored in? To be handled in code? What libraries are you using to query/update your database? What classes are you using to handle dates outside of MySql interactions? Does the same row ever return different data for the same query? If you flat-out connect to the MySql database and run the same query, what data does your mysql client give you?
|
# ? Jun 11, 2014 20:34 |
|
Gravity Pike posted:What timezone does your computer run in? What timezone do your service servers run in (if applicable)? What timezone does the MySQL server run in? What timezone do you expect dates to be stored in? To be handled in code? I've got the java application and mysql instance running on my workstation. My workstation is in San Francisco time. Dates are stored in the database in UTC. Database connections go through a c3p0 pool. We use standard java.sql.PreparedStatement to query the database with a SQL string that we build in the application, no ORM layer. I extract the timestamp from a result set using getTimestamp. It's stored in a java.sql.Timestamp and later might be converted to a java.util.date or java.util.calendar. However, for debugging, I also extract the field as a string with resultSet.getString and just print it out before doing anything else with it. For the same row I sometimes get different values. The values in the database for this data never changes. My application is processing old records that are never modified once the event that made them is over. quote:Does the same row ever return different data for the same query? If you flat-out connect to the MySql database and run the same query, what data does your mysql client give you? Yup, the same row I keep track of the row IDs in the debugging output, that's the heart of the issue. I look at a row in a mysql client and it has a date of "2014-03-02 00:38:47" and sometimes java gets the row with a correct value of "2014-03-02 00:38:47" and sometimes it gets the incorrect value "2014-03-02 08:38:47"
|
# ? Jun 11, 2014 21:11 |
|
PlesantDilemma posted:I've got the java application and mysql instance running on my workstation. My workstation is in San Francisco time. Dates are stored in the database in UTC. Welcome to the java+mysql timestamp clusterfuck. Mysql is very helpful and stores internally the timestamp in UTC, converting it to the server's timezone when asked to retrieve the data. Your java code most likely runs in your own timezone, and java.util.Date (which Timestamp extends) has the concept of timezone, helpfully converting whatever value it gets from MySql to your timezone. And then you come into the picture, doing "time conversion" (because you wanna make sure you are only handling dates in UTC, which is understandable). Therefore, it is inevitable that somebody will step on somebody-else's toes somewhere (either using insert with now(), or converting a date twice, or parsing a string or ... something somewhere will gently caress up). Solution #1: set your servers (all of them , web server, db server, etc.) to UTC and don't worry about it. Solution #2: In your java application set the default timezone to UTC (this only works if you ask the JVM to give you datetime): TimeZone.setDefault(TimeZone.getTimeZone("UTC")) in a ServletContextListener. Tell your java application that the server is in UTC (modify jdbc url): serverTimezone=UTC&useTimezone=true Tell mysql that it itself is in UTC: http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html Solution #3: Screw mysql dates and store longs (millis converted to whatever timezone you want). I honestly hope that everything that i said here is wrong and that there is a better/easier way. So far i couldn't find the answer anywhere on the internets. I locally implemented solution #2 but in production everyone is UTC so i don't have to worry. But locally, even then, sometimes i get weird dates. edit: I also moved all my timestamps to DATETIME, but still there are weird behaviors sometimes on the local machine. Volguus fucked around with this message at 23:24 on Jun 11, 2014 |
# ? Jun 11, 2014 22:03 |
|
Hold on, is the issue that you get the wrong timestamps, or is the issue that you get the wrong raw results back? If you're sometimes not getting the same data from a database that no one else is using and which you're not modifying, something is more wrong than the timezones. Are you sure you're not somehow connecting to a different DB occasionally?
|
# ? Jun 12, 2014 15:41 |
|
rhag posted:Solution #2: MySQL is already running in UTC. When I do a select now(); then I get "2014-06-12 17:38:06" when my workstations time is "2014-06-12 10:38:06". And I've put TimeZone.setDefault(TimeZone.getTimeZone("UTC")) at the top of my application, but the problem still persists. I don't set the serverTimezone&useTimezone in my jdbc, I'll try adding that on the next run. Volmarias posted:Hold on, is the issue that you get the wrong timestamps, or is the issue that you get the wrong raw results back? If you're sometimes not getting the same data from a database that no one else is using and which you're not modifying, something is more wrong than the timezones. Are you sure you're not somehow connecting to a different DB occasionally? I think I get the wrong raw results, but it must be a timezone related issue because the difference is always 7 hours. The thing that kills me is that it is not wrong every time. Here is a snip of my log files for 20 runs of the application. I just print the timestamp as soon as I get it as a string. I've filtered it to one row, #151281. On 4 of the runs the time was 11:05:41, but the time in the database is 03:05:41.
|
# ? Jun 12, 2014 18:54 |
|
|
# ? May 27, 2024 16:44 |
|
Any chance that server is hosed up and is having its time changed constantly (like, say several times per second) between local time and UTC?
|
# ? Jun 12, 2014 19:05 |