Java Q:
I like CSS for simple web pages but loathe it when it comes to real world sites because you get css explosion and lots of repeating.
I am tempted to use Sass and or Compass but they are Ruby programs which will most likely require some interesting Maven + JRuby love to get working for Java Web app dev. This also makes it difficult if you are using Eclipse or any IDE that supports synchronization with a running web app.
Is there a better alternative for the hell that is CSS in the hell that is Java?
I went down the same road recently using LessCss, a similar technology. At first I tried to embed JRuby in my build lifecycle. But unfortunately Maven + JRuby is a monster, it's slow, huge and buggy (half the time it wouldn't even start because it would complain about the file path it was running on).
Fortunately, there is now a JavaScript port of LessCss, which I now embed via Mozilla Rhino. I describe the process in this blog post.
Yesterday though I took it to the next level, making a Maven LessCss Plugin to minimize POM configuration and code duplication. Unfortunately I can't share it because it's proprietary code for my current client, but the solution is simple:
Use GMaven to create the Plugin, create an abstract base mojo that calls the LessCss compiler and several concrete implementations that configure the base mojo for different resource sets:
e.g.
lesscss:compile compiles from all
<resources> to
${project.build.outputDirectory}
lesscss:test-compile compiles from
all <testResources> to
${project.build.testOutputDirectory}
lesscss:war-compile(compiles from
all src/main/webapp to
${project.build.directory}/${project.build.finalName}
, the exploded war directory)
So while I can't help you with SASS (apart from you asking the auth
or to port it to Groovy, Java or JavaScript), I think I've shown you a feasible alternative.
Of course you can also implement a Maven Plugin in java without Groovy (also embedding the JavaScript via Rhino), but I think it's easier in Groovy.
I ended up using wro4j.
Highly recommend the library as it will handle many things like less css and coffee CoffeeScript.
A good solution for using sass with eclipse is answered in this question.
The Sass command-line interface is very thorough. If you call out to sass --update in your build rules, you can just use the standard Sass executable (either via Ruby or JRuby) without having to integrate it directly into your build.
Related
I have a Java application (a quite large one with many external .jar dependencies as well as dependencies on images) and I need to package it up so that someone can double click to run, for example. Or something easy like that.
It uses Java Persistence, so it requires a sql connection which is specified in the Persistence.xml file in the Java Project.
How can I package this up? I was thinking:
the installation process should validate that the user has MySQL installed and if not, direct them to install it
the installation process could ask the user to enter credentials for any database and then I could update the Persistence.xml at run time
These were two ideas I had...but I wasn't sure if there was a known solution to this problem. Any help would be much appreciated!
I think you should take a look at embedded database solutions, like H2. Also, you can package your application using maven's shadowing or jar plugin, having the jar-with-dependencies profile activated.
This will nicely rid you of checking for database servers running on the client machine, and also will give you the proper means of bundling the application in one nice JAR, albeit a little large.
Maven is a build ecosystem and toolset especially designed for building Java applications and executing the code -- and generally doing whatever else you can imagine that's possible to do with and to your code.
It has a rich API for developing plugins and many developers have exploited this feature. There are numerous plugins for building -- and launching -- and packaging your application as well as helping you manage your applications dependencies.
Maven's shadowing comes in the form of maven-shade-plugin, available here. What it does is that it helps you create a single JAR file from all your dependencies. Also, there is the maven-jar-plugin which offers a profile jar-with-dependencies. It is also accessible from here.
H2, on the other hand is a full-fledged RDBMS. This is the website: http://www.h2database.com/html/main.html, and here is a tutorial.
You can find information on embedding the database here:
How to embed H2 database into jar file delivered to the client?
Embedding the Java h2 database programmatically
h2 (embedded mode ) database files problem
I would also suggest you use a combination of H2/Hibernate/Spring which is a very easy setup and provides you with really rich features and an easy-to-use API.
I hope this helps you :)
Building a sophisticated installer that checks lots of dependencies, and runs on lots of different platforms (which I assume you want) is complicated.
I suggest that you look at an installer generator; see What is the best installation tool for java?
Another alternative that I've seen in a few products is to write a (non-GUI) installer or configurer in a scripting language like Perl.
I wrote an installer using ANT, but has no GUI. Also, I used Iz Pack (good option), so I think that depends on how smart do you want it to be, if you are supposed to use it, or a non-technical person, etc.
I'm investigating zeromq as a message passing solution in a java project, but I find the instructions on java binding somewhat difficult to follow. http://www.zeromq.org/bindings:java
I am unfamiliar with java bindings, so these may be stupid questions, but can someone help me understand:
Why do I need to install anything?
Will jars I build on one machine work on another system? I need this application to be portable.
If so, why do I need to build my own jars to begin with?
I feel like the instructions provided on zeromq require base familiarity with building C projects that I lack, so perhaps I am just being dense, but this seems like a lot of work.
As a fellow user of the Java binding of ZeroMQ, I sympathize. ZeroMQ is definitely one of the more challenging Java dependencies to manage. In it's heart of hearts, ZeroMQ is native C code and the Java binding is a (relatively) light weight wrapper around a JNI interface to the core ZeroMQ library and this is why it is complex to deploy.
As an aside - if ZeroMQ is a good match for your application, it's well worth the trouble because there really is nothing quite like it. Unfortunately this means you need to go through all these steps to get it working so you can decide if it is what you really need.
ZeroMQ for Java is based on three components:
libzmq - the core ZeroMQ library (DLL - required for any language, not just Java)
jzmq - the native portion of the Java binding (DLL)
zeromq.jar - the java portion of the Java binding (JAR)
Will jars I build on one machine work on another system? I need this application to be portable.
Yes. The jar will be portable. You can build it on any machine and deploy it on any other. However thats the easy part. The hard part is creating the various DLLs that are required and those are not portable. Let's say you want to support Windows, Mac and Fedora Linux. You will need native development environments on Windows, Mac and Fedora and build the DLLs for each platform you want to support.
I don't know enough about Linux to say whether a DLL built on one distribution (say Fedora) will run on another (say Debian). If not, then you have more work ahead.
Anyhow, your application will be portable - ZeroMQ and JZMQ can run on a huge number of platforms - but you will need to have tight control over your deployment process to ensure that when you install each platform, the jar and the appropriate set of DLLs are installed, and they are installed in the right place.
Why do I need to install anything?
Technically you don't. But I think they recommend doing the make install step so that the include and library files are where the compilers expect them and also so that Java can load them when it is time to run your program.
If so, why do I need to build my own jars to begin with?
I'm not a committer so I cannot say for sure. I expect part of it is developer efficiency - they would rather be improving the code than creating jars for users who could create the jars themselves.
More importantly - since the jars are not enough and you have to build the DLLs anyways, it makes more sense to build the jars and DLLs together. That way you are certain the JNI wrapper has exactly the right native methods implemented in C to match the native declarations in the Java wrapper class.
Good luck. Hope this helps.
Personally I do think pre-made JARs would go a long way to helping 0MQ in java. While I work in Java at many sites, they do not provide MSVS and having to go through such a lengthy setup just to get a dll and jar seems counter productive to me.
You can also look at JeroMQ (Pure Java implementation of libzmq).
JeroMQ is a full Java stack that uses the same protocol and API of ZeroMQ and is an official project of the community. It makes life a lot simpler for Java users since there's no JNI, no C++ to build. It does everything ZeroMQ does except PGM multicast.
I am a full time rubyist, really enjoying rails, Sinatra, etc. Currently, however, I find myself working on a Java/TomCat/JSP project.
I was hoping someone could help me find tools, articles, books, and any other resources that will make me more comfortable?
I'm aware that Java is very different from Ruby, and the communities, likewise, are very different. That being said, all of the documentation around Java (that I have found) is a mess, and discovery is very difficult in this community.
Things I'm specifically looking for:
development environment setup tips
logger, logging, colorful output, best practice, etc
library resources and documentation
easy to navigate documentation for Java SE 6
anything you have found that makes your daily life better
Thanks!
If you are joining an existing Java project then you probably want to take a look at the tools already in use and get an existing developer / co-worker to bring you up to speed with them as a first port of call.
Having said that, here are my top tips:
Get comfortable with one of the main Java IDEs. Eclipse (my personal choice), Netbeans or IntelliJ are all excellent and very powerful tools once you get to know them. The refactoring / code navigation tools are probably better than anything you are used to in the Ruby world, they will help you a lot. Java is a lot less painful with a good IDE setup.
Learn Maven - this will take some time investment but it is extremely powerful for automating your dependency management and build process. Once you get it working you will save a huge amount of time on project / build management. Maven also provides automated access to the equivalent of Ruby gems through the various public Maven repositories.
And here are some particularly useful resources:
Java tutorials - good to get an introductory feel for the core Java libraries.
Java 6 API - useful as a reference resource for all the classes and functionality available in core Java (a lot of this is also provided via the IDEs)
JSP Documentation - for the JSP / Java EE aspects
As a little side note don't forget to learn about JSTL and Expression Language.
first of all you are on the right road to discover how elegant Java EE is. since you adressed various topics i will divide my answer into different parts :
Development environment:
Without further talk i will advise you to directly go and pick your eclipse Java EE Juno (last release) version, however if you'd like to have a look at other IDEs you can either check NetBeans 7.2 (last release) or IntelliJIDEA 11.2 Ultimate (last release i know of and that I have). Basically Eclipse has tons of plugins and features and backed up by a very great, large and passionate community.
[ i personally tried NetBeans, and IntellijIDEA, but felt more comfortable with Eclipse because of its look, features, cool color theme etc]
For JSP and HTML, CSS ,JS stuff, i however recommend the great IDE of Jetbrains Webstorm it has zen coding as well as many many other things like fast auto completion and support for many frameworks.
Lastly, pick up Sublime Text 2 as a text editor for quick edits or to just check a source file, it has a very beautiful layout and support for many languages as well as tons of plugins.
Ressources and documentations :
All the Java API specifications are available for offline viewing for free in Oracle's website and come packaged with the various SDK that are available there.
The easy to navigate documentation :
Eclipse IDE makes it very easy to attach JavaDoc and Source to the different jar files that make up a JDK, that said, your learning and coding experience will be greatly increased once you've set that up.So when you type Connection for example in IDE, you can simple hold Ctrl command then right click on it and the source code of the class implementation would be opened in a different tab. yes yes it's the power of the open source world :)
Concerning tips and tricks :
I'll recommend you use //TODO comments as Eclipse has support for them and you can setup your own TODO comments in settings, also you can use TASK comments, you've Mylyn too to manage your bugs, tasks either locally or connect to your favorite bug and issue tracker through a connector since many connectors are available for such purpose. Add to this list the possibility to configure bookmarks to help you manage your source files when they become full of lines.
About Tomcat:
Well if your goal is to make Java EE applications that do not require the advanced features of the Java EE specification, then you can use the sweet Tomcat, it's easy to use and configure and a well known web container.
However if that's not the case, and you wanna specialize in Java and spend lots of time to try to understand the ins and outs of this huge specification, you are likely to need a certified Application Server that supports all Java EE components. There are lot of them available, but since you asked for advise and I am here giving my modest suggestions I would advise you to pick the GlassFish Application Server, it's Open Source, and once you install it on Eclipse IDE for example, it will be bundled with both Java EE 5 and Java EE 6 API doc. This means no time to be wasted on browsing different tools and tabs, you will have everything grouped inside your Eclipse IDE so that you are 100% on the tasks at hand.
p.s: if you've any more questions please feel free to ping me.
Any good tip or trick :
Have fun with Java, because you will be learning everyday something new :)
p.s: i didn't mention any framework, because by the time you get used to Java EE you will be in position to pick the one that suits your needs. Also forgot to mention JUnit (Testing Framework) and a great eclipse plugin EClemma for code coverage (much better than Cobertura/eCobertura and easier to use), and of course you can try Maven as the other post mentioned, or try Apache Ant as build tool.
If you're coming from a Rails background, I'd be prepared for some initial frustration. Setting up projects in an IDE can be time consuming, and generally it's going to be more painful to get things like a basic web+app server up and running using Tomcat than using Ruby.
For a REPL, I would recommend Groovy (and indeed it comes pre-installed on Intellij) but you can also use BeanShell. Grails, or groovy on rails, is probably the closest thing we have to a Rails-like environment.
As others have said, with Java, using an IDE is really best. I like Intellij IDEA, but eclipse and NetBeans are also good.
For build and dependency management, Maven is probably as close as we have to standard, although I have heard nice things about Gradle.
There are entirely too many logging frameworks in java, use whatever your project currently uses, probably log4j or SLF4J. learn how to change log levels across the board, and also at a package level.
In terms of libraries, Google's Guava makes my life better on a daily basis.
The best "tips, tricks and general best practices" book on java is Josh Bloch's Effective Java. For documentation, the Javadoc is the authoritative source. Learn to read and write good javadocs.
For Test Driven Development, jUnit is probably the most widely used library, a very popular library is mockito, which also happens to be my favorite.
I have a java project which I'm hoping to package and sell. How can I create a .msi file which will install my program on other windows computers?
If there are any tutorials, please direct me to them. I'm also using Eclipse if that has any bearing on how to create the .msi file.
Thanks
I've been using WiX extensively for creating MSI packages. It has quite a steep learning curve, but once you know what you're doing, it is very powerful. You said earlier that it needs Visual Studio installed, but I think it's just .NET 3.0, not the whole IDE.
I used this WiX tutorial when I got started, and it's got pretty much everything you need in there if you want to go down this route.
If you're after something simple, search for a tool called WixEdit on SourceForge. This has a GUI for building MSIs - it's not perfect, but pretty easy to use and produces professional results.
I'll repeat, WiX has a very steep learning curve, and if you're just after a simple way to package your application, NSIS might be easier; or, you could use the standard IExpress.exe tool built into Windows to create a self-extracting .exe (but they don't "feel" as good as an MSI).
There's nothing special about Java apps when it comes to creating MSI's other then you have to make sure you have a JVM/JRE installed just like you have to make sure the .NET framework is installed for .NET applications.
Your question is too broad to be able to answer. Implicit in your question is "What tool should I use?" and once that's decided "How do I make an MSI using this tool?"
For the first question, check out:
Windows Installer Authoring Tools for Developers
Use NSIS: http://nsis.sourceforge.net/Main_Page . It creates executable file that will do the same thing, and it is free.
If you specifically want to create an MSI package, and assuming you don't want to pay for something like InstallShield, look at Wix. http://wix.sourceforge.net/
I believe you want to look at Native Packaging, which according to this link was first introduced with JavaFX 2.2
https://netbeans.org/kb/docs/java/native_pkg.html
Since it seems to be official Netbeans docs, I imagine it is sanctioned by Oracle. Here is the counterpart for Mac for interested readers.
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
Has anyone successfully developed a "native" Palm WebOS app using GWT?
How do you setup your development environment and how did you interface with the mojo framework?
I was thinking one setup might be to create 2 projects: a GWT & a Palm OS project.
Setup your build to copy the results from you GWT compile into the Palm OS project.
Probably want to target your GWT builds at Safari.
I guess you would want to generate Java wrappers for the Mojo framework.
Please understand, I don't mean to offend you, but ... at first glance, this sounds like a really bad idea to me. GWT sacrifices some things to be able to do the cool stuff it does, but some of those things it sacrifices (eg. efficiency) seem very likely to be problems on WebOS. Not to mention that GWT is designed for "normal" (web browser) JS, and WebOS JS has some significant differences (in terms of the core types available and such).
Not saying it's impossible or anything, but just ... there's probably a reason you've had this question up for a week and haven't even gotten a single response.
Actually, there's no reason it shouldn't work, provided you add the requisite PalmSystem.stageReady(); code into your app's index.html file.
ie:
<script type="text/javascript">
if (window.PalmSystem) {
PalmSystem.stageReady();
}
</script>
If you've packaged the application properly, you can actually write an app in raw JS and HTML, without ever using the Mojo or enyo frameworks. You just wouldn't be able to access MojoDB, or other similar system resources. It follows that a GWT project should work as well, with the exact same tweak.