Auto compile SCSS in netbeans plain java project - java

I am working on a small pet-project which is primarily a java desktop application. It has a embedded web server (tomcat) to allow for remote control.
I have made the design decision to go all out with modern HTML technologies, netbeans has been able to provide all the relevant IDE features required EXCEPT SCSS auto-compile ( this works perfectly well on a HTML project) but this is a "Java Application" style project (as I want to embed all the static html/css/js content inside my jar deployable and then drive my desktop application via REST.

I guess you may be intressed in compiling your project with libsass. There are two implementations for Java. In this case it is easily integrated in the compilation step.
If you are not satisfied with it, you can integrate a frontend task runner into your working environment. Consider different options: Grunt, Gulp, etc.
I personally use Grunt for my daily routine. When speaking about Grunt, you will need to install two tasks: grunt-sass (it is different from grunt-contrib-sass) and grunt-contrib-watch. The second task compiles your .scss or .sass files on file-change. In this case you can have your .jar file filled only with desired .css files built for you by a task runner.

Related

Copy compiled binary files to remote system

I'm developing simple Java application in Eclipse Oxygen. I would like to ask Eclipse to copy binary files to testing machine automatically when it builds. How to achieve that? How to run script on remote Linux machine that restarts application when binary is copied?
UPD
Since Eclipse builds project very often I would like to have Deploy functionality according to request. How to achieve this option?
Look at the 'Builders' page of the project 'Properties'.
You can add an 'Ant' script or a program to be run when the project is built along with the other builders.
Builders normally run quite a lot so you may want to turn 'Build automatically' off.
It is also possible to write an Eclipse plugin which contributes additional builder types - but that is more work.

How to get Java standalone app with eclipse? [duplicate]

I've recently started learning SWT (on class #4, to be precise) due to business requirements, and previously I had been developing with Swing for 2 years.
We deployed Swing applications as jars with resource dependencies. In SWT, what are the deployable forms and equivalents?
I have questions but since my training is online, I'm on a course-ware and there is no instructor, except StackOverflow:
Can SWT apps be deployed as independent EXE's? And what's with the "Eclipse EXE" thing people talk about? Does it mean that all SWT outputs will be Eclipse based EXEs? Or can they be completely independent EXEs?
If the answer to 1 is yes, how does the compiler produce native win32 executable code? This is one area where I'm thoroughly confused. Typically, a deployable jar is fed to the VM which reads the manifest and does its stuff, but an EXE as output? What's really behind the scenes?
How are external resource bundles managed? At the time of deployment?
Internationalization support?
Thanks.
Deploying an SWT application is exactly like deploying a Swing app, with the addition of several jars and a native library. You must currently be using some tool to make exe files for your Swing app; that tool may or may not be competent to also package up a native code library. It is unlikely that the tool is creating 'native win32 executable code'. Rather, it is packaging up Java class files along with the JRE and a stub Windows PE file.
SWT is developed as part of Eclipse. Eclipse has the Rich Client Platform, or RCP. If you build your Java application as an RCP application, you can use the Eclipse tools to generate an executable package for Windows (or anywhere else). It is not a single executable, it's a directory with an executable in it. However, you don't have to use Eclipse to use SWT.
An RCP application has to use much more than just SWT. It has to be constructed as a set of OSGi bundles that depend on the core Eclipse platform. Once you have such a thing running inside Eclipse, there is a wizard in Eclipse that will create a Windows 'executable' (a directory containing your code in JAR file(s), a lot of Eclipse code in JAR files, the JRE, and a PE .exe stub). You can automate that process from ant, though I've never done it myself. You will need to do book-length reading to get up to speed on all of this, I fear.
There no difference between SWT and Swing in terms of resources and internationalization. Other Eclipse-related libraries include an I18N discipline, but not the core SWT. You just use locales and property files as in any other Java application.
SWT is not Eclipse-based, but the Eclipse UI is SWT-based. Eclipse uses the SWT library for its drawing. It is used a GUI library from the Eclipse consortium, available for many systems. If you want to deploy your normal Java Application with an SWT GUI you just add the corresponding libs and .dll's or .so's. Therefore, everything you can do (deployment) with Java respectively speaking Swing, can be done with SWT, if you provide the according libraries. There are tools and ways to compile everything into .exe's but that is not necessarily needed.
I do not really get the Eclipse EXE thing you are talking about, but eclipse just provides a starter exe, which is basically just a wrapper. Otherwise, some people refer to Eclipse RCP als Eclipse EXE but this is not correct. You CAN use the Eclipse RCP to base your App and this would use SWT as UI library. But you can use SWT all by yourself just as library without the Eclipse trail.
I hope this helps.
You can use a java to EXE wrapper like this one http://jsmooth.sourceforge.net/.
Hope it helps.
Basically you need to get your project running with the conventional java -jar command.
Then create an exe bootstrap program that runs the command when you double click it.
Extra things can be done like checking JVM versions inside the exe program.

How to continuous UI development in java?

So I come from ruby on rails background.
I am working on this java project.I am fairly new to java.
I maybe wrong but It seems unlike other technologies ,one compiles the project in a war file then deploy's that on tomcat.
The original assets are in src directory that are be checked in the source directory.
Where as to make any changes in assets files that being css/javascripts/images one need to
make changes in the target directory of the tomcat to preview them on the browser.
This makes development tricky and complex as I can't use branches, since branches work on src directory of my local repository but the changes I make are in the target directory. Also I would like to use sass and haml like features in java. What frameworks or other web servers or any other strategy are my options .
I have heard of groovy on grails but for some reason we want to stick to java the language
Look into using a build tool like maven or gradle to build your project. They both have a jetty plugin with a jettyRun goal that will run your project out of your source directory using embedded jetty. So if you are making changes to the assets, you just have to refresh the browser.
Another alternative is to configure tomcat to serve your assets up as static files from your workspace while you're doing development.
Or as #DaveNewton suggested, you can use your IDE to auto deploy

How are Java applications deployed in the "real world"?

As a novice to the world of Java programming, this question has always boggled my mind. I first believed that all Java files were compacted into applets and then ran, but I soon realized that this isn't always the case. Could someone explain to me how we actually interweave our Java applications into a real product of everyday life?
TL;DR: How do we implement our code for practical usage?
It depends on the application. There are many options depending on how you want your users to use your app. Usually it's packaged as a jar or a specialized jar (war, ear).
In theory, you could zip the raw directory structure with your .class files in it and provide a shell script/instructions that run the java command for the user. I don't recommend this because it's kind of unprofessional and requires you to maintain a shell script for each OS you want to be able to run the program on.
Jar files are used to package libraries but you can also have a manifest file in it that says, "When someone double clicks/executes this, run this class". That class can start up a GUI or be a headless task that responds to the parameters, etc.
You can have applets, like you said. These programs are run in the user's browser.
You can have a war file, which is a way to package a web application. You give this to a web server and it knows how to deploy it so that you can visit the web pages. An example web server/container is tomcat or jetty.
You can have an ear file which can contain other war files inside it. This is used for applications that need other parts of the javaee functionality (ejbs, jms queues, etc.). An example of an application server is jboss or glassfish.
There's also java web start apps. These are apps you can run by visiting a webpage, but they get downloaded to your computer and run on the user's computer (instead of on the server's backend, like in a war/ear).
There's also javafx. I don't know anything about that though. By skimming the FAQ, it appears to be Java's answer to Adobe's Flex. You configure UI components with an xml configuration. I'm not sure what format JavaFX apps use, but it does say, "Deploy on the desktop or in the browser".
As Sotirios Delimanolis mentioned in a comment below, you can build these files with build systems like Ant or Maven. You can also build them "by hand" with the tools that come with the java/javaee sdk. For example, you should have a jar command in your path if you installed the sdk. Here are some details of these build systems:
Maven
High level (you tell it what to build, not how to build it)
Much more than just a build system. It also has dependency management, etc.
Opinionated (it uses convention over configuration, each config file generates 1 artifact, etc.)
Ant
Low level (you tell it how to build things)
Flexible
Config files can do whatever you want, build as many artifacts as you want
Easy to learn
SDK tools
Always up to date. EG: Very rarely, maven/ant may not be able to set a configuration option
Difficult to remember commands
Very low level
By itself, not repeatable (EG: unless you build a script, you will have to type the jar command yourself each time)
Applets never really caught on and are very rarely used nowadays.
Simple applications can be deployed as "executable" JAR files , which are basically ZIP archives with additional metadata that tells the JVM which class contains the main method to run. They can be run on the command line using the -jar option, or in most desktop environments by double-clicking (this requires a JVM to be installed as well).
Desktop applications can be deployed via Java Web Start or installers like IzPack or Install4J, but Java desktop applications are not very common either.
Most Java software nowadays runs only on servers (web servers or app servers). They are typically deployed as WAR or EAR files, which are also ZIP archives containing classes and other resources. These applications then run inside a server component following the Servlet or EJB standards.
If the application is mean to run on a client, it is packaged as an executable JAR, then further packaged as an Application Bundle (Mac), maybe wrapped in an exe (Windows), or paired with an executable script that will launch the JAR and set any required VM arguments.
If it is part of a web application, then it will be packaged as a WAR or EAR and placed into the appropriate location on the web server.
If it is simply a library, then it is usually packaged as a JAR (non-executable) and distributed as such for integration into larger projects.
applets and then ran, but I soon realized that this isn't always the case
Actually, applets are rare nowadays and their use is discouraged.
Create an executable jar, a war which is dropped into a web server or a library that is used by another project that is one of the previous two.

Eclipse: Is it possible to publish Javascript edits to an external Tomcat instance

I am converting an application from Flex to Javascript. My workflow within Eclipse for Flex was to use Maven to start my Java web app in Tomcat and then have Eclipse configured to compile edited Actionscript files to a SWF and save it to my exploded WAR directory (that Maven/Cargo uses).
It worked very well for a long time allowing me to edit actionscript source code, flip over the browser, refresh the screen and see the changes.
I am new to Javascript however, and am struggling to get the same workflow up and running. The part I don't understand is how to tell Eclipse that I would like my edited Javascript files to be written out to a particular directory (that contains the exploded WAR). In my WAR project (a WTP dynamic web project) there is something that looks like a Javascript build path called "Javascript resources", but there is no output directory.
I would really like to continue to run Tomcat and Jetty via Maven if at all possible. I realize I can do what I want via WTP (M2E-WTP), but would prefer to use Maven/Cargo.
Denis's suggestion to create custom builder is probably best solution if you want to continue using pure Maven/Cargo approach with Eclipse.
If you are deploying to an exploded war directory, then another similar idea would be to use a File Synchronization plugin. These will automatically copy modified files to configured folders. See:
http://andrei.gmxhome.de/filesync/
https://wiki.onehippo.com/display/CMS7/Use+Filesync+Eclipse+plugin+for+faster+turn+around
-------------
FWIW, I don't think Maven:Tomcat/Cargo plugins are ideal for real-time web development, especially on the frontend side of things. They are useful mainly for controlled deployments or bootstrapping a server without initial setup. My thoughts:
Eclipse WTP used to be great for real-time web development, but I stopped using it a few years back as it just got way too hard to make it work correctly in a Maven environment. Fwiw, my preferred approach these days looks like this:
Do not install or use Eclipse WTP.
Use m2eclipse to integrate Maven with Eclipse.
Use Maven to do clean builds and generate exploded WAR directory in target folder.
Setup independent Tomcat server to load webapp from the exploded target folder.
I suspect the tomcat setup/startup could be integrated into Maven. It's not worth the extra complexity to me though.
Then, I configure JRebel (automatically via Maven) to handle java and web resource file changes. With this setup, I almost never have to redeploy or restart Tomcat. All changes (java, html, js, etc.) are seen immediately.
I think the same setup could be used without JRebel (for non-java files only) by configuring the web source folders as source folders in Eclipse with custom target output path being the corresponding directory in the exploded war directories. If that didn't work, then it would definitely work by using the custom builder or file synchronization solutions mentioned above.
Eclipse introduces the concept of "builder" to build a project. It comes with hardcoded builders such as the java compiler or the war builder of WTP.
But eclipse also enable to setup your own Builder using ant files : on your project, right click the project properties, go to section Builders, click on the new button.
You can use arguments to your ant file and use variables defined in by eclipse to build them
Do not forget to fill the refresh tab if you want eclipse to by notified of the produced files.
Do not forget the fill the Build options tab, section "Specify working set of relevant resources" in order to have your builder called each time a source used by the build file is changed inside eclipse.
Also go to the "targets" tab to specify during which type of build phase your ant file is called and which target is called.
I knwo this solution may not be the best for you since your build process will be described more than once but it may help you achieve your goal.

Categories