How can I validate CSS on internal web pages? - java

I want to check internal web pages, so I cannot use the W3C validation service directly. I managed to run the XHTML validator locally, however, I have some problems with the css-validator. I do not really want to setup Tomcat or Jigsaw in order to be able to run Java servlet, and the commandline option gives me an error message
Exception in thread "main" java.lang.NoClassDefFoundError:
org.w3c.tools.resources.ProtocolException at
org.w3c.css.css.CssValidator.main(CssValidator.java:164)
How can I validate local CSS on a Linux box?

That jar is runnable, but it needs some extra libraries.
Examine the MANIFEST.MF file:
$ unzip -p css-validator.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.0
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
Main-Class: org.w3c.css.css.CssValidator
Class-Path: . lib/commons-collections-3.2.1.jar lib/commons-lang-2.6.j
ar lib/jigsaw.jar lib/tagsoup-1.2.jar lib/velocity-1.7.jar lib/xerces
Impl.jar lib/xml-apis.jar lib/htmlparser-1.3.1.jar
You need all the jars mentioned in Class-Path. You can download them from the maven repository using this script:
#!/bin/bash
set -e
mkdir -p lib
curl -LO http://www.w3.org/QA/Tools/css-validator/css-validator.jar
echo "\
http://repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
http://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
http://repo1.maven.org/maven2/org/w3c/jigsaw/jigsaw/2.2.6/jigsaw-2.2.6.jar jigsaw.jar
http://repo1.maven.org/maven2/org/ccil/cowan/tagsoup/tagsoup/1.2/tagsoup-1.2.jar
http://repo1.maven.org/maven2/org/apache/velocity/velocity/1.7/velocity-1.7.jar
http://repo1.maven.org/maven2/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar xercesImpl.jar
http://repo1.maven.org/maven2/nu/validator/htmlparser/htmlparser/1.2.1/htmlparser-1.2.1.jar\
" | while read url shortname; do
if [ -z "$shortname" ]; then
shortname="${url##*/}"
fi
curl -L -o "lib/${shortname}" "${url}"
done
After doing that, it works:
$ java -jar css-validator.jar --output=soap12 file:badcss.html
{vextwarning=false, output=soap12, lang=en, warning=2, medium=all, profile=css3}
<?xml version='1.0' encoding="utf-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<m:cssvalidationresponse
env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:m="http://www.w3.org/2005/07/css-validator">
<m:uri>file:badcss.html</m:uri>
<m:checkedby>http://jigsaw.w3.org/css-validator/</m:checkedby>
<m:csslevel>css3</m:csslevel>
<m:date>2013-03-12T06:40:09Z</m:date>
<m:validity>false</m:validity>
<m:result>
<m:errors xml:lang="en">
<m:errorcount>1</m:errorcount>
<m:errorlist>
<m:uri>file:badcss.html</m:uri>
<m:error>
<m:line>8</m:line>
<m:errortype>parse-error</m:errortype>
<m:context> h1 </m:context>
<m:errorsubtype>
exp
</m:errorsubtype>
<m:skippedstring>
100%
</m:skippedstring>
<m:message>
Property fnt-size doesn't exist :
</m:message>
</m:error>
</m:errorlist>
</m:errors>
<m:warnings xml:lang="en">
<m:warningcount>1</m:warningcount>
<m:warninglist>
<m:uri>file:badcss.html</m:uri>
<m:warning>
<m:line>5</m:line>
<m:level>0</m:level>
<m:message>You should add a 'type' attribute with a value of 'text/css' to the 'style' element</m:message>
</m:warning>
</m:warninglist>
</m:warnings>
</m:result>
</m:cssvalidationresponse>
</env:Body>
</env:Envelope>

You can invoke the W3C validator from the command line:
Command-Line use
Any computer with Java installed can
also run the validator from the
terminal/console as a commandline
tool. Download the css-validator.jar
jar archive (or build it with ant jar)
and run it as :
java -jar css-validator.jar http://www.w3.org/
Note : the css-validator.jar file must
be located at the exact same level as
the lib/ folder to work properly.
Update: To get it to work, I checked out the full distribution from CVS and ran ant using the included build.xml. It downloaded all dependencies except for servlet.jar. To deal with that, I downloaded the binary distribution of Tomcat 6 and extracted it. Then, I edited the build.xml for css-validator to reflect the location of servlet.lib:
<property name="servlet.lib"
value="E:/Downloads/apache-tomcat-6.0.20/lib/servlet-api.jar"/>
Then ran ant again. This produced the css-validator.jar file in the top level of the directory checked out from CVS with the lib subdirectory containing the other jars it depends on. Then, I was able to run the validator successfully:
C:\Temp\validator\2002\css-validator> java -jar css-validator.jar http://www.unur.com/

For the lazy, here's a script I wrote to do what Sinan suggests:
#!/bin/sh
# W3C CSS Validator Install Script --------------
# installs W3C CSS Validator
# requires: ant, wget, javac
# see: http://jigsaw.w3.org/css-validator/DOWNLOAD.html
# see: http://esw.w3.org/CssValidator
# see: http://thecodetrain.co.uk/2009/02/running-the-w3c-css-validator-locally-from-the-command-line/
# see: http://stackoverflow.com/a/3303298/357774
##wget "http://www.w3.org/QA/Tools/css-validator/css-validator.jar"
#sudo aptitude install -y ant # uncomment if you don't have ant
CVSROOT=:pserver:anonymous:anonymous#dev.w3.org:/sources/public cvs checkout 2002/css-validator
mkdir 2002/css-validator/lib
TOMCAT6_VERSION='6.0.45'
wget "http://www.apache.org/dist/tomcat/tomcat-6/v$TOMCAT6_VERSION/bin/apache-tomcat-$TOMCAT6_VERSION.tar.gz"
tar xvf apache-tomcat-$TOMCAT6_VERSION.tar.gz
mv apache-tomcat-$TOMCAT6_VERSION/lib/servlet-api.jar 2002/css-validator/lib/servlet.jar
rm -rf apache-tomcat-$TOMCAT6_VERSION apache-tomcat-$TOMCAT6_VERSION.tar.gz
cd 2002/css-validator
ant jar
# usage example: java -jar css-validator.jar "http://csszengarden.com/"
That should work, at least until the next software dependency update breaks the ant build script (feel free to parameterize versions).
Hope this helps!

You can now use the new Linux command line tool htmlval for checking HTML and CSS. It should definitely work for validating local CSS on a Linux box.
Note: I'm the developer.

Related

Java - No Main Manifest Attribute, in App.jar error even though MANIFEST.MF file is in /META-INF

I have been trying to get this to work, but it won't. I went through the Archive Manager and found the MANIFEST.MF file in App.jar/META-INF/ so I don't know why it says there isn't one!
chmod-ing it with chmod +x ./App.jar and running ./App.jar returns
bash: ./App.jar: cannot execute binary file: Exec format error
Running Linux Mint 20 (Based on Ubuntu 20.04) With OpenJDK 11.
Use java -jar App.jar to run the executable JAR file.
There is a way to make JAR files directly executable using the binfmt_misc kernel feature but most users/linux distributions don't bother to set it up.

How to create symlink in rpm to files provided by external rpms?

I'm trying to package two symlinks to corresponding jars provided by external dep1.rpm and dep2.rpm. These are declared as dependencies in my-app-extra.spec:
Requires: dep1
Requires: dep2
I have my %install symlinking their jars (%dep1jar, %dep2jar):
%install
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}/%{my_app}
pushd $RPM_BUILD_ROOT%{_javadir}/%{my_app}
for jar in %dep1jar %dep2jar
do
ln -sf ../"${jar}" "${jar}"
done
popd
but the rpmbuild fails with:
ERROR: link target doesn't exist (neither in build root nor in installed system):
/usr/share/java/my-app/dep1.jar -> /usr/share/java/dep1.jar
Add the package providing the target to neededforbuild and Requires
// same error for dep2.jar
error: Bad exit status from /var/tmp/rpm-tmp.31253 (%install)
Is there any way to circumvent this rpmbuild check?
Background
I have a java application that (optionally) requires two external libraries to provide extended functionality. To install these libraries, I have created dep1.rpm and dep2.rpm that store the jars under %_datadir/java and an additional my-app-extra rpm that should symlink those under %_datadir/java/my-app (following some apparently established java-packaging conventions under linux).
But I'm failing to find how to force rpmbuild to build this rpm without declaring the external libraries as BuidRequires and having them installed first.
What I want
This is in summary what I'm after (simplified, as the complete solution involves versioning):
/usr/share/java/dep1.jar (from dep1.rpm)
/usr/share/java/dep2.jar (from dep2.rpm)
/usr/share/java/my-app/dep1.jar -> ../dep1.jar (from my-app-extended.rpm)
/usr/share/java/my-app/dep2.jar -> ../dep2.jar (from my-app-extended.rpm)
Note: I'm now exploring the possibilities of rpm subpackages, but I somehow expect this to be possible without subpackaging.
I could make it work 'touching' the targets and excluding them from the files. In my-app-extra.spec:
%install
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}/%{my_app}
pushd $RPM_BUILD_ROOT%{_javadir}/%{my_app}
for jar in %{dep1jar} %{dep2jar}
do
# touch! rpmbuild aborts the build if symlink targets missing!
touch ../"${jar}"
ln -sf ../"${jar}" "${jar}"
done
popd
# more stuff ...
%files
# ...
# Exclude dummy (touched) files!
%exclude %{_javadir}/%{dep1jar}
%exclude %{_javadir}/%{dep2jar}
%{_javadir}/%{my_app}/%{dep1jar}
%{_javadir}/%{my_app}/%{dep2jar}

Unknown argument: -release

I am facing an issue with Unable to execute dex: method ID not in [0, 0xffff]: 65536), so I found this post that can help me resolve this error. But as you will see in that post that it needed ant installation. So I started learning the docs for ANT and completed installation of ANT.
But now I cannot fire ant -release command, although I was able to fire ant -debug. The complete log of ant -help and ant -version has been attached to this if it could help anyone. You can see in here that is doesn't have ant -release command:
D:\xxxxxandroid\NilayNew\xxxxxx>ant -help
ant [options] [target [target2 [target3] ...]]
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-silent, -S print nothing but task outputs and build failures
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ''
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ''
-f <file> ''
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from
${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
-autoproxy Java1.5+: use the OS proxy settings
-main <class> override Ant's normal entry point
D:\xxxxxandroid\NilayNew\xxxxxx>ant -version
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
Can anyone suggest me what went wrong or what is it that I am missing ?
Thanks in advance
ant -debug, ant -help and ant -version are out-of-the-box funcionality of ANT.
Please read ANT documentation from: http://ant.apache.org/manual/index.html
ANT by defalut use build.xml file that contain configuration (what 'methods'/procedures are invoked). ANT is looking for '-release' target in that file and if doesn't exist, it crash...
Check build.xml looking for '-release' target
Recheck what command you need to execute
Why you want to launch ant -release?

Can I try/catch this error: "An unexpected error occurred while trying to open jar"

I am working on my first non-trivial Java app. It was started by a co-worker, but she didn't have time to finish, so I took it over. I decided to use Buildr as my build tool: https://buildr.apache.org/
First, to start with empty target directories, I do:
buildr clean
Then I:
buildr --verbose compile
which gives me:
(in /Users/cerhov/projects/openz/lofdg/buildr_fdg, development)
Compiling buildr_fdg
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company
cp /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/resources/com/company/students.txt /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company/students.txt
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company
cp /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/resources/com/company/scores.txt /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company/scores.txt
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company
cp /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/resources/com/company/behavior.txt /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company/behavior.txt
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company
cp /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/resources/com/company/schoolDates.txt /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company/schoolDates.txt
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company
cp /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/resources/com/company/assignments.txt /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources/com/company/assignments.txt
touch /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/resources
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/classes
Compiling buildr_fdg into /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/classes
Note: /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/com/company/Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
touch /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/classes
Completed in 0.926s
This gives me my ".class" files. Now I want to package this up as a jar, so I:
cerhov : 15:26:04 : ~/projects/openz/lofdg/buildr_fdg $ buildr --verbose package
which gives me:
(in /Users/cerhov/projects/openz/lofdg/buildr_fdg, development)
Building buildr_fdg
Packaging buildr_fdg
Packaging buildr_fdg-1.0.0.jar
rm /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/buildr_fdg-1.0.0.jar
mkdir -p /Users/cerhov/projects/openz/lofdg/buildr_fdg/target
Running integration tests...
Completed in 0.212s
Then I do this:
cerhov : 15:26:56 : ~/projects/openz/lofdg/buildr_fdg $ ls target/
and I see a new Jar file has been created:
buildr_fdg-1.0.0.jar classes resources
so I:
java -jar target/buildr_fdg-1.0.0.jar
but I get:
Error: An unexpected error occurred while trying to open file target/buildr_fdg-1.0.0.jar
I'd like to get more info so I wrapped my whole main() function in a big try/catch statement:
public static void main(String[] args) {
try {
// all my real code goes here, but I have deleted it for clarity
} catch (Exception e) {
e.printStackTrace();
}
}
Then I re-compiled and re-packaged, but I still get the same error. I am unclear how I can force the app to give me more info.
I wanted to see if my manifest.txt got into my jar, so I copied the jar to another folder, cd'ed to that folder, and:
jar xf buildr_fdg-1.0.0.jar
and then this:
cat META-INF/MANIFEST.MF
showed me:
Created-By: Buildr
:
Manifest-Version: 1.0
Main-Class: com/company/Main
Which looks right. Maybe I can add in a classpath, though Buildr seems to have found all the files.
How do I force the app to give me more information about the problem?
UPDATE:
I tried adding this line to the manifest:
Class-Path: /Users/cerhov/projects/launchopen/lofdg/buildr_fdg/src/main/java/com/company
Then I re-compiled and re-packaged. But this:
java -cp buildr_fdg-1.0.0.jar com.company.Main
gave me:
Error: Could not find or load main class com.company.Main
So I tried every variation:
/Users/cerhov/projects/launchopen/lofdg/buildr_fdg/src/main/java/com/
/Users/cerhov/projects/launchopen/lofdg/buildr_fdg/src/main/java/
/Users/cerhov/projects/launchopen/lofdg/buildr_fdg/src/main/
/Users/cerhov/projects/launchopen/lofdg/buildr_fdg/src/
/Users/cerhov/projects/launchopen/lofdg/buildr_fdg/
None of which work. Am I suppose to aim the classpath at the source directory or the target directory?
Why is Buildr unable to manage this for me? It does find all of the files and it does bundle them all into the jar, so it knows where everything is.
I recreated the problem and was able to correct it by manually removing the colon (:) that appears by itself in the manifest file. Don't know why buildr is putting it there. This describes a way of possibly overriding the manifest file in buildr: https://buildr.apache.org/rdoc/Buildr/Packaging/Java/JarTask.html My reputation is too low to post a comment so unfortunately I can only post it as an answer. Hopefully this helps.
It looks like there are a couple of problems with the manifest file. One is that you have a stray ':' as mentioned by kharyam above and the other is that the Main-Class attribute is in incorrect format. It should look like the class name (i.e. "Main-Class: com.company.Main"). If you can post the part of the build file that defines the package we may be able to help further.

Adding multiple dependent Jars using Javafxpackager

I'm having issues adding multiple packages in the command line.
javafxpackager -createjar -outfile outjar -srcdir /dest/to/src -classPath
libs/library1.jar:libs/library2.jar -appClass pathto.MainClass -v
I've tried with spaces and multiple -classPath flags and obviously I've tried the colons as well. I'm working in Ubuntu and the program works great in Eclipse, but when I package it, it works until I try to do something that requires an external library. If I use only one I can do that function fine, but need multiples to work fully.
If anyone can shine some light on this I would greatly appreciate it.
Instead of:
-classPath libs/library1.jar:libs/library2.jar
use:
-classpath "libs/library1.jar;libs/library2.jar"
Whatever it is that parses the JavaFX-ClassPath that is created in the manifest by the packager doesn't like you having : to separate the libraries. When you use a ; instead in the -classpath argument, the generated JavaFX-ClassPath will use a space to separate the libraries and the runtime will then be able to use both libraries.
Here is a sample manifest I generated using the JavaFX packager on OS X (which worked for me).
$ jar xf HelloWorld.jar
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
JavaFX-Application-Class: HelloWorld
JavaFX-Class-Path: lib/phrases.jar lib/friend.jar
JavaFX-Version: 2.2
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main
Jar containing the manifest was generated using the command on OS X 10.8 Java 1.8.0-ea-b113:
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/javafxpackager -createjar -classpath "lib/phrases.jar;lib/friend.jar" -srcdir . -outfile HelloWorld -appclass HelloWorld

Categories