Creating BSS files from CSS in JavaFX 9 [duplicate] - java

I have Ubuntu Linux system with Sun JDE 9.0.1 and I need to convert some of Fx's CSS files to binary form from console.
But when I execute the command:
javapackager -createbss -outdir . -srcdir .
I got an error:
Error: jfxrt.jar needs to be on classpath for -createbss and for
-createJar without -nocss2bin
My JDK is properly installed. I have all necessary modules (including FX).
Any ideas how I can avoid a stupid bug and I make the packager to do it's job?
If I run javapackager from "/usr/lib/jvm/java-9-oracle/jmods" directory it completes without error. So right now I am using an ugly fix, search the modules directory, make it current, run packager from there. But that's damn ugly.
javapackager doesn't accept any other parameters but outdir, srcdir and srcfiles so I can't force loading or looking path for the jfx module. But may there is some trick with environment variables or something that can make the fix less ugly?
P.S. Running from jmod directory or removing "-srcdir" from the parameters eliminates the error, but the packager doesn't generate any output files (even if I specify input files with "-srcfiles"). Seems as javapackager is completely broken in createbss mode. Does anyone use it with Java 9?

I've checked the sources - javapackager from JDK 9.0.1 is totally broken! Use executable file from Java 8. I filled out a bug report to Oracle and all of a sudden they were very surprised (nobody noticed that one of the basic function ot a core tool is broken yet?!).
TEMPORARY SOLUTION: Use the javapackaged tool from JDK 1.8. All you need is the executable itself and you can put at any place. I put it right into my project tree (under "tools" directory) and call from a building script. WARNING! Use this replaced executable for "createbss" ONLY! Use the regular one for all other things!

Related

Journey browser Java Chromium Embedded framework throwing error?

I am trying to use a library called Journey browser which uses the Java Chromium Embedded Framework. I first created a Java Maven Project with Netbeans and I edited the pom.xml to match the values on the library's guide, which is here: https://github.com/CodeBrig/Journey, to add the maven dependencies. (No errors detected by Netbeans) I then built the project to download the maven dependency and put their default code (modified slightly) in the main class. Netbeans found no errors in the code. However, when I run the project I get a "no chrome_elf in java.library.path". I think this has something to do with embedding JCEF, but I am not sure how to add this to the "java.library.path" in Netbeans.
How do I fix this "chrome_elf" problem?
Also, if I am able to fix this will it be an error for production if someone doesn't have "chrome_elf" installed?
For Windows
This happens because the chrome_elf.dll (on Windows) file cannot be found.
Java is looking for this file on java.library.path - which (on my machine, anyway) refers to all the locations referenced by the Windows %path% environment variable.
One way to fix this is to download one of the pre-built distributions from that GitHub page (for example the Windows one, referred to here):
https://github.com/CodeBrig/Journey/releases/download/0.4.0-78-assets/jcef-distrib-windows64.zip
Then unzip the resulting jcef-distrib-windows64.zip. In the win64\bin\lib\win64 directory under that main directory you will find the chrome_elf.dll you need - and other binaries which are also needed.
Add this directory to your path - either by adding it to the Windows environment variable or via java -Djava.library.path=....
For example, the path may be similar to this:
C:\your\path\to\jcef-distrib-windows64\win64\bin\lib\win64
This should allow you to run the demo code provided in the JourneyBrowser class. A browser window should open as a result.
Here is the browser:
The above steps worked for me - and the only files I needed to keep from the (large) distribution download were those in the jcef-distrib-windows64\win64\bin\lib\win64 directory. It's possible that I already have some other dependencies which may be needed - so I cannot guarantee this process will also work for you.
For Linux (and MacOS)
I have not tried this on a Linux machine. But in that case, I believe you will need to download and unzip the jcef-distrib-linux64 release - and then point to the jcef-distrib-linux64\linux64\bin\lib\linux64 directory, containing libcef.so and other libraries.
Similarly for MacOS, there is a distribution which can be downloaded and unzipped.
Alternative
An alternative is to simply use the pre-built distributions provided on GitHub, using the commands provided. Obviously, in this case, you will not be creating your own customized implementation (so, no JourneyBrowser class).
copy scr/native/Release to jcef_build/native/Release from the default output directory of VS.check whether the Release exists in java.lib.path

How Do I Install a Jar?

I was reading some documentation for db2jcc4.jar when something caught my attention in the following (emphasis added):
The following command will retrieve the JCC driver version if executed from the command line:
java com.ibm.db2.jcc.DB2Jcc -version
Or for drivers that are not yet installed:
java -cp ./db2jcc.jar com.ibm.db2.jcc.DB2Jcc -version
All I have is the db2jcc4.jar file - it didn't come with an installer or anything. I can run the second command and it works fine, but the first gives me this stack trace:
Exception in thread "main" java.lang.NoClassDefFoundError: com.ibm.db2.jcc.DB2Jcc
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Jcc
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:665)
at java.lang.ClassLoader.loadClass(ClassLoader.java:644)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
Could not find the main class: com.ibm.db2.jcc.DB2Jcc. Program will exit.
This tells me that the jar is not yet installed. In all the time I've worked with Java, I've never heard of installing a jar. How can I make it so that the first command works instead of having this issue and printing a stack trace? How can I install a jar?
It looks to me like the second command includes a flag, -cp, which modifies the classpath. I'm guessing that means that all I need to do is move my jar file into a specific directory. I tried putting it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.33.x86_64/jre/lib but that didn't make it so the second command would work. I'm stumped and would appreciate any suggestions for where exactly I need to move this jar for it to be considered installed.
There is no such thing as "installing" a jar. To be used by a Java application, jars have to be accessible in the classpath. Take a look at this link:
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
By installing the java jar they meant that the jar is available to your program (physically present and found in your class path). If the Path to the jar was not setup then you have to options:
+ copy the jar file to your existing path
+ include the jar file in the command line
java -cp <path_to>/db2jcc.jar com.ibm.db2.jcc.DB2Jcc -version
It looks to me like the second command includes a flag, -cp, which modifies the classpath. I'm guessing that means that all I need to do is move my jar file into a specific directory.
I would say that you need to explicitly include the jar file itself on the classpath. Personally, I generally do not attempt to "install" a jar as you describe, but rather create some sort of script or executable jar file that will facilitate the establishment of the correct classpath.
EDIT: In the context of deploying code to an application server, then "installing" the jar would make sense--typically there's a shared lib folder available on an application server where you can simply drop the jar and the code will become available to all the applications running on the server--this can become a bit of a management headache, however and I often will prefer to have a completely self-contained deployment over sharing jar files between applications--YMMV, however.
You commented thus:
Your link has this comment - (Classes that are part of the JRE, JDK platform, and extensions should be defined through other means, such as the bootstrap class path or the extensions directory.) - How would I go about adding the jar through that?
That is a bad idea, for (at least) the following reasons:
Putting stuff into the extensions directory is going to potentially affect every Java application that you execute. Not just the application that you are trying to "install". In some cases, this may to lead to unexpected breakages due to conflicting versions, etcetera.
When you update the Java installation, the standard installer, RPM or whatever is going to create a new installation tree. But it won't copy anything from the existing installation. So a Java update is likely to break any application that depends on stuff in "extensions".
If you try to solve the above problems by "embedding" a Java installation, you risk losing track of where your Java installations are. This makes applying Java security patches problematic. And of course, embedded JREs take up a lot of disc space ... at ~100Mb a time.
I suspect that "Installing a JAR" is a poorly chosen terminology that likely means placing the jar on the JVM classpath" - i.e. in order to make it available to an application. The recommended ways of doing so vary depending on the Java platform (whether it is a server platform or a client side platform).
For example, on a Java EE server, you could package the jar file within the application, or define it as a shared library, and attach it to the server's classloader or the application's classloader to make it available to that application. Third party applications, such as various IBM products, will come with their own instructions as to how to 'install' a db2jcc4 driver.

How to run ant script where ant is not installed?

I have an ant script which compiles java code and executes it but when I run it on a machine where ant is not installed it does not execute nor compile. Is there any way to do this?
Thanks
No, there is no way to do this.
Basically, running a program require having this program installed. No mater what program it is.
Copy bin and lib directories from a Ant -package to your project path and run "bin\ant".
Or for example you project path could contain:
build.xml
src
software\ant\bin
software\ant\lib
You can run "software\ant\bin\ant" in you project path.
You can try to create something similar to the gradle wrapper for ant.
Basically, it's a batch/shell script and a simple jar that only need a valid JAVA_HOME to run. When you launch this script it download gradle if required (i.e. not already available at a well known location), then it execute your gradle build.
Imagine someone saying, "I have a C/Python/Perl/C++/Whatever program I want to compile. Is there anyway to compile that C/Python/Perl/C++/Whatever program without having to install C/Python/Perl/C++/Whatever?"
The answer would pretty much be no. You need Ant to interpret the Ant build files.
Fortunately, installing Ant is pretty straight forward. You download the ZIP file from Ant's Distribution Page, then unzip it into some directory (preferably one without spaces in the name. C:\Program Files\Apache Ant isn't a good choice, but C:\apache-ant would be fine.
Now, you set two environment variables, ANT_HOME pointing to where you installed Ant, and JAVA_HOME pointing where you installed the Java JDK. (Windows comes with the Javaruntime, but you need to have the Java JDK which you can get from Oracle.) This can be done by going into the System Control Panel->Advanced
WARNING: When installing Java Developer Kit (JDK), be very, very careful not to accidentally install the Ask Toolbar. Java does this by default.
Once that is done, set your PATH (again via the PATH Environment variable to include %ANT_HOME/bin and %JAVA_HOME%/bin at the beginning of your path.
Then, running ant on the command line in a Console window will run Ant. The whole procedure takes about 10 minutes to do.

Setting javacc to work with command prompt

I've been trying to set up javacc but am having problems. When I type javacc adder.jj (in the directory where adder.jj is) I am getting "'javacc' is not recognized as an internal or external command, operable program or batch file".
To my understanding I have to go to environmental variables, TEMP and change PATH to have C:\javacc-6.0\bin; added to the start. (I extracted the javacc zip to C:). I have tried this and restarted my computer with no luck. I also tried adding C:\javacc-6.0\bin\lib but again no luck. I did this when I installed java to get cmd to recognise javac and it worked!
This is probably trivial but I just can't get it to work!
Thank you
Henry
In the version 6.0 the bin directory is missing the scripts which run javacc. That is why you are getting the error from the windows command prompt.
What you have is a jar file javacc.jar located in the lib directory. All you need is to add that jar file to your classpath and run the java.exe and pass the main class which runs javacc, the later happens to be named javacc too, so to run javacc just proceed like this:
cmd> java -cp C:\javacc-6.0\bin\lib\javacc.jar javacc
In the latest version they seem to have forgotten to add the scripts in the bin folder of the package. You can download version 5.0, it containes all the script files you need, among others a file with the name javacc.bat, this is the one the window commad prompt is looking for and not finding in your case.
Of course, you can just copy those scripts from the 5.0 version to the bin directory of the 6.0 version, they will also work. and since you already have set the path to contain C:\javacc-6.0\bin then you can run it like you have tried before, without closing the command prompt window or even restarting your whole computer!
Edit - new links
The links above are unfortunately no longer valid, luckily the content has been moved to github. here the new links:
Project url: https://javacc.org/
Project url on github: https://javacc.github.io/javacc/
Earlier versions: https://github.com/javacc/javacc/branches/
Solution
Download version 5.0, copy the files that come in the bin folder, except the lib folder (they are .bat files)
Paste those files in the same location, but in version 6.0 and resolved issue.
The error is that they did not add the executables in the bin folder.
open cmd
cd to the directory where the javacc (calculator_2.jj) file loacted
type in the cmd java -cp D:\S2018\CS661\javacc-6.0\javacc-6.0\bin\lib\javacc.jar javacc calculator_2.jj

Simple swing application. The jar file runs on my computer, but not others

This is my first question, so apologies for any mistakes. I'll try and give all the info I can. Basically I've written a simple swing application which just loads in image into a JPanel and displays it. I'm using Netbeans 7.1 and I have the latest version of the Java SDK.
Anyway, I've used the "Build" feature in NetBeans 7.1 to deploy my application into a Jar file. When I double click the Jar File on my PC, it runs without a problem. However when I put it on other computers (Tested on 2 others so far, both with the most current JRE) it fails to open, citing the following error:
could not find the main class: swong.Startup. Program will exit
swong is my package name, and Startup is the location of my main method. I have checked the manifest file which is created with Netbeans' build, and it[the manifest] does indeed contain the location of my main method class.
From searching, I've come across similar issues in which the classpath is set wrongly, but I don't understand how this could cause my particular error.
If someone could help me, I would be over the moon. I've been studying java for a year or so, and I've got a good handle down, but I've NEVER been able to make a Jar that runs on a computer which wasn't my own. So, 10 points and thanks in advance.
xo.
EDIT: Thank you for the responses. I'm doing shift work and swamped, but I will test and poke with these responses tomorrow and provide more information. Thanks again. xo
I had d same problem while distributing my app. There is 1 solution that you create a batch file with 'java -jar AppName.jar' and asking user to double click on this batch file to execute your app. What i did was to provide a JRE installation exe(eg: jre_1.7.0) with your app.
Now create a Batch file (install.bat) in which write following commands
jre_1.7.0 -> this will install jre on user's pc
set path="C\Program Files\Java\jre_1.7.0\bin"
java -jar yourAppName.jar
Why i installed JRE because different people have different JRE versions installed. So this makes it difficult to set path to the installed JRE's bin folder & calling the 'java -jar' command. Hence as you know which folders your JRE installation will create hence it is easy to set path and execute your jar file with 'java-jar' command.
Check that your jar file has the following structure (at least)
jarfile.jar
|---------- swong
|---------- Startup.class
|---------- META-INF
|---------- MANIFEST.MF
It seems like the class "Startup" is missing. Maybe your jar only contains the .java files, not the compiled classes.
This error message can be a mistakable java7 error, when you try to start java7 compiled classes with a different Java Runtime Environment then java7. Have you validated, that your .jar is started within a Java7 environment on those other test machines? Sometimes it happens, that you have installed different versions of JREs and you might not be sure which one is actually started.
To check which enviroment is used, you can check in your registry for the following value:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
this should point to your latest JRE. Or if you'd like to stay compatible to java6 as well, define the appropiate compile level in your build environment.

Categories