I'm trying to call gate program from command prompt am using example from following code in this link:
http://gate.ac.uk/wiki/code-repository/src/sheffield/examples/StandAloneAnnie.java
Step 1 : I replaced StandAloneAnnie with a name "mario"
Step 2 : I added .jar and .zip files in classpath of my java program and a single document path in the argument.
Step 3 : complied it with no errors but with an exception , called the program in CMD prompt and I get following error !
Exception in thread "main" java.lang.reflect.InvocationTargetException.....
Caused by: gate.until.GateRuntimeException: Cannot guess GATE Home. Please set manually
I tried both methods
Method 1 : using Gate.setGateHome(File) using following code before Gate.init()
public static void main(String args[]) throws GateException, IOException {
// initialise the GATE library
Out.prln("Initialising GATE...");
Gate.setGateHome(new File("E:/Gate/Installation/"));
Gate.setPluginsHome(new File("E:/Gate/Installation/plugins/"));
Gate.setSiteConfigFile(new File("E:/Gate/Installation/gate.xml"));
Gate.init();
Out.prln("...GATE initialised");
Method 2: using this in cmd -Dgate.home=path/to/gate/home
java -jar mario.jar -Dgate.home=E:\Gate\Installation
More Information :
I'm using Java 1.7.45
My gate is in E:\Gate\Installation folder.
In Java i get following exception :
Exception in thread "main" java.net.MalformedURLException: unknown protocol: e
at java.net.URL.<init>(URL.java:574)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at mario.main(mario.java:98)
Am I doing something wrong in this. Please help.
Thank you.
Try Putting GATE_HOME in environment variable directing to the Gate Root directory, This might solve your problem.
Also look for the references If you have changed/renamed any variable.
My suggestion is that first you try to run with default names then change/update name as required
Related
So I'm trying to write a Java program using the SAP BO SDK. When I try to create a session, using a predefined class from the SDK, I get a nullPointerException. I copied my code 1 to 1 from an SDK tutorial. Here is my code:
public class Program {
public static void main(String[] args) {
try {
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
...
}
}
}
When I run that code (I commented everything else out for testing), I get the following error:
Exception in thread "main" java.lang.NullPointerException
at com.crystaldecisions.celib.classloader.ClassLoaderHelper$2.getResourceAsStream(ClassLoaderHelper.java:102)
at com.crystaldecisions.celib.classloader.ClassLoaderHelper.getResourceAsStream(ClassLoaderHelper.java:149)
at com.crystaldecisions.sdk.framework.internal.SessionMgr.initializeSystemProperties(SessionMgr.java:258)
at com.crystaldecisions.sdk.framework.internal.SessionMgr.<init>(SessionMgr.java:253)
at com.crystaldecisions.sdk.framework.internal.CEFactory.makeSessionMgr(CEFactory.java:94)
at com.crystaldecisions.sdk.framework.CrystalEnterprise.getSessionMgr_aroundBody0(CrystalEnterprise.java:121)
at com.crystaldecisions.sdk.framework.CrystalEnterprise.getSessionMgr_aroundBody1$advice(CrystalEnterprise.java:512)
at com.crystaldecisions.sdk.framework.CrystalEnterprise.getSessionMgr(CrystalEnterprise.java:1)
at myprogram.main(Program.java:18) <-- Line 4 in my code example above
Does this mean that there is an error in the libraries provided by the SDK? Or that I somehow imported those incorrectly? Is it possible to get any more information from this error code?
Thank you for any help or guidance you can provide.
EDIT: The tutorial used: http://bukhantsov.org/2011/08/getting-started-with-businessobjects-java-sdk/
The issue was that I was referencing JAR files directly from my Program Files. Copying the files to a local folder in my workspace, and referencing them from there fixed the problem.
I have built a DLL which I am attempting to wrap Java code with, however I am having some troubles with running my Java program. I wrote a simple test DLL and Java program and am producing the same error, and although there are plenty of resources regarding NoClassDefFoundError online I can't seem to solve mine with any troubleshooting methods.
Here is my D:\Test1.Java file
public class Test1 {
static {
//System.loadLibrary("HeyLand");
System.load("D://HeyLand.dll");
}
public native void displayHeyLand();
public static void main (String[] args) {
Test1 t = new Test1();
t.displayHeyLand();
}
}
After compiling, attempting to run D:\Test1.classresults in the following:
D:\>java Test1.class
Exception in thread "main" java.lang.NoClassDefFoundError: Test1.class
Caused by: java.lang.ClassNotFoundException: Test1.class
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
Could not find the main class: Test1.class. Program will exit.
Why I am stumped :
1. I have set my classpath to be D:\, so I believe my class definition would be in the classpath, and I do not see how my compile-time and run-time classpaths could be any different.
2. I don't see how this could have anything to do with static initialization, and I believe the exception would look different.
Perhaps I'm just missing something incredibly simple, I am very newbie with Java.
Any help is greatly appreciated!
The classpath environmental variable is taking precedence over that in the java run command. You need to specify the class location (as well as removing the .class file extension)
java -cp . Test1
Java normal syntax for executing class file is
Java [<options>....} <class-name> [<arguments>....]
For example
java com.package.name.Test1
here how compiler works
1. Compiler search for complete class name
2. Load that class
3. check for main method - in the same class
4. Call main method with passed arguments in command line string.
Now following are the possibilities why your class may not found main method.
1 - forgot to include package name
I am new developer in java but I found when I run application using eclips or intellJ editor it gives different path and package name and execute code as I noticed it on command line edior. So make sure you are including package name
For example:
java com.package.name.Test1 instead of
java Test1
2. File name or pathname rather then class name
As I noticed output file is in different location. That why class file path was different.
java Test1.class
java com/package/name/Test1.class
3. Typo
also I noticed you are using
static {
//System.loadLibrary("HeyLand");
System.load("D://HeyLand.dll");
}
Is this function ? or constructor? If it is function then where is name of the function? You cant write code without any reference in classs
I need your help around JAVA RMI, i developped a sample program used to sort table. but i got this exception:
Erreur RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: ServicesTableau
and this is my Server source code :
public class Serveur {
public static void main(String args[]) {
try {
System.out.println("Server start ...");
ServicesTableauImpl od = new ServicesTableauImpl();
String url = "rmi://" + args[0] + "/ServicesTableauImpl";
System.out.println("Passe");
Naming.rebind(url, od);
System.out.println("Attente d'invocations de client / CTRL-C pour stopper");
} catch (Exception e) {
System.out.println("Erreur " + e.getMessage());
}
/*
catch(java.net.MalformatedURLException e){
System.out.println("Mauvais nom de serveur");
System.exit(1);
}
catch(RemoteException e){
System.out.println("Pas de Rmiregistry");
System.exit(1);
}
*/
}
}
That class isn't available on the CLASSPATH of the RMI Registry. The simplest way to fix it is to start the Registry in the same JVM, via LocateRegistry.createRegistry(). Store the result in a static field.
This happened to me because I didn't run rmiregistry in the same directory as the server.
I spent a few hours to successfully start the simple example form Orcale!
Hope could help you
First, I run the program on Windows
I totally copy the code from here
but i delete the package and put that three .class file together for the convince
and if you are not familar with this i hope you'd better do it, too
because when package get in, the problem will be more complicated
There are three steps to do:
1.start rmiregistry
start rmiregistry -J-Djava.class.path=./
it is for "remote interface definition"
so that the rmiregistry can find the class
then solve the ClassNotFoundException
2.run server
start java Server
then you can see the output:
Server ready
3.run client
java Client
output:
response: Hello, world!
then talk about how to deal with package
Usually the Server.class and interface.class---"remote interface definition"
should be in the same package
and you need to know how to run the .class with package
java {packagename}.Server
the classpath default is "./"
and package declare will help to locate the interface.class which is needed for Server.class
so we don't need to separately set -cp
BTW, if you try set the real classpath, you will get error instead
As for "start rmiregistry"
it has no default classpath
so we need to set it
and it should be the same as the classpath's default value "./"
In some cases, you need to move you rmi clients code (interface and main) to default package. Repeate it for server side. It can solve you problem(work with packaging in rmi is not so obvious).
The answer is for IDE based project.
you need to 'start rmiregistry' from with in the build folder.
for example:
in Intellij
open terminal inside 'target -> classes' folder
run 'start rmiregistry'
then run your server code using intellij
for eclipse I hope its build folder
This error is because of not writing security manager code, because of which the class can't get loaded.
So make sure you add code for the security manager.
If the compiler doesn't find the security manager then create a new one.Add the code in main method.
if (System.getSecurityManager() == null) then
System.setSecurityManager(new RMISecurityManager())
I've been trying to use Matlab's javabuilder package under Windows XP, but I'm getting a strange error when trying to instantiate any javabuilder class. To illustrate the problem, I've created a simple program that prints the MCRROOT and PATH system variables (to check if they're correctly set) and tries to create a MWCharArray:
import com.mathworks.toolbox.javabuilder.*;
import com.mathworks.toolbox.javabuilder.internal.MCRConfiguration;
class Main
{
public static void main(String[] args)
{
System.out.println("MCRROOT: " + System.getenv("MCRROOT"));
System.out.println("PATH: " + System.getenv("PATH"));
System.out.println(MCRConfiguration.isInstalledMCR());
MWCharArray test = new MWCharArray("Test");
}
}
When I execute the program, the output is:
MCRROOT: C:\Program files\MATLAB\MATLAB Compiler Runtime\v710
PATH: C:\Program files\CollabNet Subversion Client;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program files\MATLAB\MATLAB Compiler Runtime\v710
false
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getMCRRoot(MCRConfiguration.java:77)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ModuleDir.<clinit>(MCRConfiguration.java:51)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getModuleDir(MCRConfiguration.java:56)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1447)
at com.mathworks.toolbox.javabuilder.MWUtil.GetUnknownClassID(MWUtil.java:1258)
at com.mathworks.toolbox.javabuilder.MWClassID.<clinit>(MWClassID.java:41)
at com.mathworks.toolbox.javabuilder.MWCharArray.<init>(MWCharArray.java:75)
at Main.main(Main.java:11)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.get(MCRConfiguration.java:70)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.<clinit>(MCRConfiguration.java:72)
... 8 more
Java Result: 1
First of all, are MCRROOT's and PATH's values correct? I've tried google for finding out how to set MCRROOT, but there are conflicting results: some sources say that I should include de version dir, others say the opposite. Also, why is the isInstalledMCR method returning false? I've double-checked the MCR installation (and even uninstalled and installed it to be sure), so why isn't the library finding it?
Thanks on advance for any help!
Edit: I've also tried setting MCRROOT with no version string, and it also fails.
Just wild guessing! Java is messing around with strings, while your 'mcrroot' contains white spaces. I might change the mcr install path to something like C:\MATLAB\MATLABCompilerRuntime\v710, omitting any white spaces and special characters.
I've found the solution, so I'm post a self answer for future reference: Besides adding the javabuilder.jar to the program's classpath, you also have to add the path to the MCR's runtime libraries to the java.library.path JDK parameter.
My mistake was that, instead of setting the path as the path to the libraries at the MCR installation directory (On my case, C:\MATLAB\MCR\v710\runtime\win32), I copied the runtime directory to my project's dir and used it instead. It seems that the javabuilder library uses the java.library.path variable the guess the MCROOT, what would explain the weird "StringIndexOutOfBoundsException".
What am I doing wrong here:
class Helo {
// main: generate some simple output
public static void main (String[] args) {
System.out.println ("Hello, world."); // print one line
System.out.println ("How are you?"); // print another
}
}
When I go into terminal I do:
cd ~
javac Atempt2.java (//that's the file name)
java Atempt2
and then it gives me this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Atempt2
So all in all this is what I do and what happens:
david-allenders-macbook-pro:~ davidallender$ cd ~
david-allenders-macbook-pro:~ davidallender$ javac Atempt2.java
david-allenders-macbook-pro:~ davidallender$ java Atempt2
Exception in thread "main" java.lang.NoClassDefFoundError: Atempt2
david-allenders-macbook-pro:~ davidallender$
I am very new at this so please explain things in a very simple manner.
Thanks.
Its been awhile since I've done any java work but I'm pretty sure your class name needs to match your file name.
javac uses the class name to generate the output not the filename.
So it will generate a Helo.class classfile.
java will take a class name and call the main function in the corresponding class file, here Hello.class.
The ClassNotFoundError is thrown because javac never generated an Atemp2 classfile as there is no Atemp2 class in your source file.
Rename your Atempt2.java to Hello.java to get going, then:
javac Helo.java
java Helo
See here for more discussion and the reasoning.
change:
class Helo
to
class Atempt2
in your source file.
A .java file that declares a class must have the file name match the declared class name.
The filename must match the name of the public class defined in the file. In this case, you would either have to name the file "Helo.java" or renamed the class to Atempt2.
This is the very basic to start with java programming.Any program you write the name of the file must match with the public class of the program.
Here in your program public class of the file is Helo so your file name must be Helo.java.Here the compiler is able to compile but JVM will search for Helo.class file to run. As there is no Helo.class file you are getting runtime Exception Exception in thread "main" java.lang.NoClassDefFoundError: Atempt2
to complement josefx's answer.
The argument to the compiler (javac) is the name of the file or files to compile (as you did).
On the other side, the virtual machine (java) gets the name of the class whose main method is to be executed.
One option would be
javac Atempt2.java // the file name
java Helo // the class name
Normally it is a good idea to have the file named the same way as the class. For public class this is a must (checked by compiler).