I create an Applet and I generate the jar file with the following code
JAR FILE
"c:\arquivos de programas\java\jdk1.7.0_05\bin\jar" cvf C:\Users\lucas\Desktop\AbrirAplicativo3000.jar C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\WebcamApplet.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\QRCodeProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\QRCodeListener.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\OpenCVWebCam.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\CVImageProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\AbstractProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\ImagePanel.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\LabelPanel.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\LoadingScreen.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\StringsResourceTranslator.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\BufferedImageLuminanceSource.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\CommandLineRunner.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\GUIRunner.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\ImageConverter.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\MatrixToImageWriter.class
and I singed the JAR file normally.
I put the JAR file in a visible HTTP (http://www.netimoveis.com/AbrirAplicativo3000.jar)
In my ASPX page, I'm calling the APPLET following this code
<applet code="com.colorfulwolf.webcamapplet.WebcamApplet"
archive="http://www.netimoveis.com/AbrirAplicativo3000.jar, http://www.netimoveis.com/AbrirAplicativoAssinado3000.jar"
height="550" width="550">
</applet>
But when I try to run, I got the error
Incompatible magic value 218774561 error in applet
Someone can help me ?
Your AbrirAplicativo3000.jar is not correctly packaged. If you look inside, it has this structure:
META-INF/
C:/
Users/
lucas/
workspace/
WebcamApplet/
bin/
com/ --> this is where the jar should start from.
...
Try using the -C option on the jar command like this:
"c:\arquivos de programas\java\jdk1.7.0_05\bin\jar" cvf C:\Users\lucas\Desktop\AbrirAplicativo3000.jar -C C:\Users\lucas\workspace\WebcamApplet\bin\ .
Also it's not the first time that this magic number comes up on SO, although it seems more related with a bad URL. However I did download the jar with your supplied URL so just try re-packaging it.
The magic value error means that the class file doesn't start with the integer 0xCAFEBABE as it should. You probably had a transfer or compression problem.
If you can open the file in an hex editor, you may look for those bytes.
Related
I am trying to generate C header file for JNI (Linux). I read documentation and questions on javah, but I still get the same error
Error: Could not find class file for 'org.sqlite.core.NativeDB'
I think I have very obvious mistake but I really don't see any... So, I need to generate header file from the NativeDB.class and the path is:
/u/users/maas/user123/sqlite/sqlite-jdbc-3.21.0/target/common-lib/org/sqlite/core/NativeDB.class
I go to the common-lib folder and call javah from the path of:
/u/users/maas/user123/sqlite/sqlite-jdbc-3.21.0/target/common-lib/
The commands I tried:
javah -classpath "/u/users/maas/user123/sqlite/sqlite-jdbc-3.21.0/target/common-lib/org/sqlite/core" org.sqlite.core.NativeDB
javah org.sqlite.core.NativeDB
The error I get:
Error: Could not find class file for 'org.sqlite.core.NativeDB'
I see the NativeDB.class file in the correct directory I mentioned. In the NativeDB.java (which is not in the same folder with NativeDB.class IF it is important) there is a package path:
package org.sqlite.core;
I found the issue (that was really obvious and dumb).
Commands I wrote in the question are correct. I am using USS (UNIX System Services) for Z/OS and ftp for transferring files. I didn't check that I sent .class files via ftp NOT in binary format. And for this reason Java couldn't find the classes because of wrong encoding.
All you need is just turn on the binary mode in the ftp like so:
ftp server.name.com
..login...
bi
mput *class
The bi command enables binary mode. The .class files are expected to be in this format.
I am trying to run a java file in the cmd prompt in Windows 7.
I get the error:
Error: Could not find or load main class
I actually just save a new simple file to check if there were problems with the package inside eclipse; this new file is saved just as:
C:\Users\User5\Documents\eclipse\test\Example.java
class Example {
// A Java program begins with a call to main().
public static void main(String args[]) {
System.out.println("Test.");
}
}
I changed the classpath for lucene's jar's recently, and I am not really sure if this is the problem.
There are many other threads about this issue, such as:
Could not find or load main class
but, there seem to be other concerns that solved their issues.
In this case, I have saved just a plain file in notepad, and while I can get the file to compile, and it seems to create the class file, it is still spitting this error back.
This is the dir, which seems to show that the class is there:
C:\Users\User5\Documents\eclipse\test>dir
Volume in drive C has no label.
Volume Serial Number is 3E0D-3B82
Directory of C:\Users\User5\Documents\eclipse\test
12/07/2015 10:15 AM <DIR> .
12/07/2015 10:15 AM <DIR> ..
12/07/2015 10:04 AM 301 .classpath
12/07/2015 10:04 AM 380 .project
12/07/2015 10:04 AM <DIR> .settings
12/07/2015 10:05 AM <DIR> bin
12/07/2015 10:51 AM 428 Example.class
12/07/2015 10:15 AM 162 Example.java
12/07/2015 10:05 AM <DIR> src
4 File(s) 1,271 bytes
5 Dir(s) 10,000,461,824 bytes free
C:\Users\User5\Documents\eclipse\test>java Example.java
Error: Could not find or load main class Example.java
This should to the trick - don't append .java
C:\Users\User5\Documents\eclipse\test>java Example
I think I need to make this in a larger post:
C:\Users\User5\Documents\java\test>java Example
Error: Could not find or load main class Example
I just accidentally posted the wrong copy to the original post here, but the file is not running as just a call to the file. This is not the only file I cannot get running; nothing will run in the cmd prompt, although everthing runs fine in eclipse.
Thank you'all for your help, I really appreciate you!!
C:\Users\User5\Documents\eclipse\test>java Example.java
will not run - take out the .java part and simply run
C:\Users\User5\Documents\eclipse\test>java Example
To make sure you do not have an issue with your CLASSPATH variable, do
set CLASSPATH=
java Example
If that is the issue, your classpath variable gets corrupted, you can go to the Control Panel, somewhere in the advanced section to update environment variables.
I got the same error when I needed to take inputs(arguements) at runtime using terminal/Command prompt and corrected it it by compiling and running the java class as below:
javac packageName/Example.java
java packageName/Example
NOTE: The reason for this error in my case was that the java class was created inside a package and that required compilation and execution in a different way as above mentioned.
So I've followed the instructions on the malabar-mode github page.
I have emacs packages set up, with melpa added as a an archive (which is where malabar-mode is). mvm's containing directory is in my exec-path, and I have added the following to my ~/.emacs file, as per the README's instructions:
(setq semantic-default-submodes '(global-semantic-idle-scheduler-mode
global-semanticdb-minor-mode
global-semantic-idle-summary-mode
global-semantic-mru-bookmark-mode))
(semantic-mode 1)
(require 'malabar-mode)
(setq malabar-groovy-lib-dir "/path/to/malabar/lib")
(add-to-list 'auto-mode-alist '("\\.java\\'" . malabar-mode))
However, when I start up emacs, I get:
Warning (initialization): An error occurred while loading `/Users/kalaracey/.emacs':
File error: Cannot open load file, malabar-mode
How can I get malabar mode to work? I am using Emacs 24, which has CEDET built in, so that is why I have added the above code to my ~/.emacs file (as per the instructions).
malabar-mode was added to MELPA so you do not need to install it by hand anymore.
To install
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(package-install 'malabar-mode)
(package-install 'flycheck) ;; This is optional but nice to have
In .emacs.
Because malabar-mode takes so long to load (over 30 seconds on my box), I have it delay loading until I try and find a .java file.
(defun malabar-mode-bootstrap ()
(require 'cedet)
(require 'semantic)
(load "semantic/loaddefs.el")
(semantic-mode 1);;
(require 'malabar-mode)
(load "malabar-flycheck")
(malabar-mode)
(flycheck-mode))
(add-to-list 'auto-mode-alist '("\\.java\\'" . malabar-mode-bootstrap))
Also, take a look at https://github.com/m0smith/maven-pom-mode for editing the pom.xml.
I've to "compile" compass files dynamically in my java soft'. So, following explications found on stackoverflow, I've done these steps :
Get JRuby (1.7.3), configure PATH to jruby.jar and binaries (gem, rake ...) and learn to launch ruby script from Java
Get compass and dependancies gems into a local directory, using following command line
gem install -i ./compass compass
=> So I get a directory ./compass/ containing bin, cache,doc, gems & specifications directories.
Put gems in a jar using following command line (think to use a jar name which is not the same as the gems, to avoid JRuby "require" the jar instead of the gems)
jar cf compass-lib.jar -C compass .
Write a test script test.rb in local directory to test my jar. It contains :
require 'compass'
Compass.add_configuration(
{
:project_path => '.',
:sass_path => 'styles/scss',
:css_path => 'styles/css'
},
'custom' # A name for the configuration, can be anything you want
)
Compass.compiler.compile('test.scss', 'test.css')
Execute this script with JRuby, with following command line :
jruby -I . -rcompass-lib.jar test.rb
And get this error ...
Unable to load Sass. Please install it with one of the following commands:
gem install sass --pre
LoadError: no such file to load -- jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/s
ass-3.2.8/lib/sass/../sass
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/sass-3.2.8/lib/sass/ver
sion.rb:5
require at org/jruby/RubyKernel.java:1027
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
require at org/jruby/RubyKernel.java:1027
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/sass-3.2.8/lib/sass.rb:
9
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:60
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/compass-0.12.2/lib/comp
ass/dependencies.rb:6
each at org/jruby/RubyArray.java:1613
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at test.rb:1
An idea of the problem and, maybe, of solution ? ;) Thanks by advance.
[UPDATE #1]
After Jörg W Mittag obvious suggestion, the error disapear. Thanks ;) Now, it just don't find the scss file, so it's a "normal problem" ;)
[UPDATE #2]
Having used compass with success in IRB, it's time to transpose the test through Java. So, I wrote some lines in Java to execute my ruby script, using only absolute path to avoid problems in a first time.
InputStream myFile = ISRessources.getFile("C:/Path/To/My/test.rb");
new ScriptingContainer().runScriptlet(myFile, "test.rb");
But ... how to "load" my compass-lib.jar ? What's the equivalent of the -r in JRuby ? I've tried to includ gems into jruby.jar, to add compass-lib.jar in externals jars in java build path, but both don't work, I still have :
LoadError: no such file to load -- compass
require at org/jruby/RubyKernel.java:1027
(root) at test.rb:1
Any idea ?
The error message says:
Unable to load Sass. Please install it with one of the following commands:
gem install sass --pre
I'm having some problems at runtime with some of my generated protocol buffer classes.
My project layout is as follows:
module/
protobuf-api/
proto/
com/foo/api/Service.proto
com/foo/shared/Shared.proto
org/bar/api/Message1.proto
org/bar/api/Message2.proto
The Service.proto file depends on Shared.proto and some of the Message*.proto files. From the protobuf-api directory, I run the following command to compile:
find . -name *.proto -exec protoc --java_out=java -I=proto {} \;
When I attempt to run my Service, I get the following exception:
java.lang.ExceptionInInitializerError
at com.linkedin.history.api.protobuf.HistoryServiceProtos$HistoryServiceQuery.(HistoryServiceProtos.java:544)
at com.linkedin.history.api.serializer.HistoryServiceSerializer.serialize(HistoryServiceSerializer.java:47)
at test.history.serializer.TestSerializer.testHistoryServiceQuery(TestSerializer.java:38)
at test.fwk.util.core.BaseTestSuiteCore.run(BaseTestSuiteCore.java:304)
at test.fwk.util.core.BaseTestSuiteConf.run(BaseTestSuiteConf.java:186)
at test.fwk.lispring.BaseTestSuite.run(BaseTestSuite.java:232)
at test.fwk.lispring.BaseTestSuite.callAppropriateRun(BaseTestSuite.java:265)
at test.fwk.util.core.BaseTestSuiteCore.run(BaseTestSuiteCore.java:199)
Caused by: java.lang.IllegalArgumentException: Invalid embedded descriptor for "com/linkedin/history/api/protobuf/HistoryService.proto".
at com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(Descriptors.java:268)
at com.linkedin.history.api.protobuf.HistoryServiceProtos.(HistoryServiceProtos.java:1794)
Caused by: com.google.protobuf.Descriptors$DescriptorValidationException: com/linkedin/history/api/protobuf/HistoryService.proto: Dependencies passed to FileDescriptor.buildFrom() don't match those listed in the FileDescriptorProto.
at com.google.protobuf.Descriptors$FileDescriptor.buildFrom(Descriptors.java:221)
at com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(Descriptors.java:266)
I've read the post here but I think I'm doing everything correctly. Any suggestions on why I'm having the initializer errors? I'm compiling everything with the same -I flag.
I suspect that the problem is that when you're finding the proto file, you've given it the full path, e.g. proto/com/foo/api/Service.proto but when it refers to it via the include directory, it's using com/foo/api/Service.proto
Simple fix - run this from the proto directory:
find . -name *.proto -exec protoc --java_out=../java -I=. {} \;
I must admit I can't remember a lot of the details of protoc (which I really should) but I suspect that will work.
Another alternative which may work:
protoc --java_out=java `find . -name '*.proto'`
i.e. pass all the proto files into a single call to protoc.
I had the same error type in C# and here was my problem: I called the protoc in a pre-build step in my project. There I used Visual Studio built-in macros like $(SolutionDir) and $(ProjectDir) to retrieve necessary paths. Since I referenced *.proto files from other projects, I used two --proto_path options: one for the root path (to resolve import paths) and one for the file itself. My solution file was inside a subdirectory of the root directory, so I used the relative path .. to get to the root. Proto files are always in subdirectory gen of the particular project. All in all, the command was like this:
protoc.exe --proto_path=$(SolutionDir).. --proto_path=$(ProjectDir)gen $(ProjectDir)gen\DemoFile.proto
It compiled fine, but I got the System.TypeInitializationException at runtime on calling CreateBuilder() method. The problem was that both paths $(SolutionDir).. and $(ProjectDir) (though effectively pointing to the same directory) had different textual representation due to the relative path component ... I solved the problem by consistently using the same path like this:
protoc.exe --proto_path=$(SolutionDir).. $(SolutionDir)..\My\Demo\Project\Directory\gen\DemoFile.proto
It cost me almost 3 days to narrow down and recognize the problem, so I share my solution here in hope that it will save some time for someone.