Simple jacorb program - java

I am following this tutorial to implement a server and client using jacorb. I used the same code and in step 2 when I want to compile the generated server.java class I got this error
javac server.java
server.java:11: cannot find symbol
symbol: class serverOperations
extends serverOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity
^
1 error

Add the directory containing the generated stub and skeleton code to your classpath. The JacORB jar is also required
javac -cp /path/to/stubcode:jacorb.jar:. Server.java

I would recommend asking questions about JacORB on the jacorb-developer list (http://www.jacorb.org/contact.html)

Related

How do I run java projects from the terminal? [duplicate]

I am trying to compile (from the command line) a java package that imports another package of my own. I was following a tutorial online but it seems that I get an error when I try to compile the final java file (CallPackage.java).
Here is the file structure:
+ test_directory (contains CallPackage.java)
-> importpackage
-> subpackage (contains HelloWorld.java)
Here is CallPackage.java:
/// CallPackage.java
import importpackage.subpackage.*;
class CallPackage{
public static void main(String[] args){
HelloWorld h2=new HelloWorld();
h2.show();
}
}
and here is HelloWorld.java:
///HelloWorld.java
package importpackage.subpackage;
public class HelloWorld {
public void show(){
System.out.println("This is the function of the class HelloWorld!!");
}
}
Attempted Steps
Go to the subpackage and compile HelloWorld.java with $javac HelloWorld.java.
Go to test_directory and compile CallPackage.java with $javac CallPackage.java.
This gives me an error on the last command:
CallPackage.java:1: package importpackage.subpackage does not exist
import importpackage.subpackage.*;
^
CallPackage.java:4: cannot find symbol
symbol : class HelloWorld
location: class CallPackage
HelloWorld h2=new HelloWorld();
^
CallPackage.java:4: cannot find symbol
symbol : class HelloWorld
location: class CallPackage
HelloWorld h2=new HelloWorld();
^
3 errors
How can I compile both packages? Thanks so much for any help!
The issue was that the class path needs to be set for each command (javac and java):
Attempted Steps
instead of going to subpackage, compile HelloWorld.java from the top_level:
$javac -cp . importpackage/subpackage/HelloWorld.java
compile CallPackage.java in the same way:
$javac -cp . CallPackage.java
run the file using the class path also:
$java -cp . CallPackage
NOTE: running "$java CallPackage" will give an error "Error: Could not find or load main class CallPackage"
In summary, during each step, the class path must be specified. It worked after running it as such.
Same situation to me. And I came to take over it by compiling classes at the same time.
For example, here is my project:
+ beerV1
-> classes
-> src
-> com
-> example
-> model
-> BeerExpert.java
-> web
-> BeerSelect.java
BeerExpert.java:
package com.example.model;
import ...
public class BeerExpert{
...
}
BeerSelect.java:
package com.example.web;
import com.example.model.*;
import ...
public class BeerSelect {
...
}
As you can see: BeerSelect.java is trying to import classes in com.example.model package.
At the first time, I compiled BeerExert.java first by command:
--> javac -d classes src/com/example/model/BeerExpert.java
Then:
--> javac -d classes src/com/example/web/BeerSelect.java
And the result was:
-->... error: package com.example.model does not exist
So, I knew that compiling multiple classes separately will not work in this case.
After suffering on google, I found this very simple way to solve the problem:
Just compile all at once:
--> javac -d classes src/com/example/model/BeerExpert.java src/com/example/web/BeerSelect.java
Finally, here is what I got:
+ beerV1
-> classes
-> com
-> example
-> model
-> BeerExpert.class
-> web
-> BeerSelect.class
-> src
-> com
-> example
-> model
-> BeerExpert.java
-> web
-> BeerSelect.java
Hope that helps.
Are you sure importpackage/subpackage is in your classpath?
-cp path or -classpath path
Specify where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory. See Setting the Class Path for more details.
If the -sourcepath option is not specified, the user class path is also searched for source files.
If the -processorpath option is not specified, the class path is also searched for annotation processors.
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html
It's an old topic but Google has led me to this site. For the completness, I'd like to add one bit to #Vĩnh Thụy Trần's answer on how to run the main class after compiling it into a custom folder. While it looks trivial now it took me some time to get it right.
In order to run your project, you also need to specify a path to the classes:
java -classpath <directory> your.package.name.classname
or
java -cp <directory> your.package.name.classname
Taking Vĩnh Thụy Trần's example again, the command would look like this:
java -cp classes com.example.web.BeerSelect
I hope it will help someone as I spent some time figuring it out.
(1)first compile the code
javac -d importpackage.subpackage.HelloWorld
(2) and then compile the CallPackage.java
javac CallPackage.java
delete your package folder (after pasting you code to some other folder) and then locate to the folder in cmd where you current code is and try javac -d . Helloworld.java (this will create the Helloworldclass and subpackage as well) and try same for you mainfunction code ie Callpackage.java after compiling to run the code try java Callpackage

How to include a third-party jar-file in compilation and runtime using command prompt in Windows 10?

I'm trying to understand the inclusion of third party jar files in a java project using only the command line in Windows 10.
Specifically, I try to include the file json-20200518.jar in my "project" so that I can use the java object JSONObject in the project.
My java file:
package com.mypackage.example;
import org.json.JSONObject;
class Example {
public static void main(String[] args) {
// ... program logic
}
}
location of my java file (Examp.java):
./com/mypackage/example
location of jar file:
./jars
using cmd win10 I compile:
javac -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" "C:\Users\pfort\Desktop\java\com\mypackage\example\Examp.java"
compilation is successful.
Run:
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" com.mypackage.example.Examp
I get a report:
Error: Could not find or load main class com.mypackage.example.Pokus
Caused by: java.lang.ClassNotFoundException: com.mypackage.example.Pokus
Second attempt:
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" "C:\Users\pfort\Desktop\java\com\mypackage\example\Pokus"
But the same error message comes back to me.
Where am I going wrong? Is it the wrong structure? I don't get it, the compilation is successful but the run does not work.
The compiled Examp.class file isn't part of json-20200518.jar, so you'll need to add the directory containing it to the command line. Assuming it's the current directory (.):
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar;." com.mypackage.example.Examp

Error setting classpath

I want to run an automated test-case generation tool on the class Realm.java of project Async-HTTP-Client.
I located its path:
[dario#bob async-http-client]$ find /home/dario/async/553/prefix -name Realm.java
/home/dario/async/553/prefix/async-http-client/api/src/main/java/org/asynchttpclient/Realm.java
Hence set the classpath to:
[dario#bob async-http-client]$ echo $CLASSPATH
/home/dario/async/553/prefix/async-http-client/api/src/main/java:/home/dario/async/553/prefix/async-http-client/evosuite-tests:/home/dario/testEnv/684131/prefix/rhino/lib/xbean.jar:/home/dario/evosuite/target/evosuite-0.1-SNAPSHOT-jar-minimal.jar
But when I run the command to generate tests:
[dario#bob async-http-client]$ ~/evosuite/target/bin/EvoSuite -class org.asynchttpclient.Realm -projectCP /home/dario/async/553/prefix/async-http-client/api/src/main/java:/home/dario/testEnv/684131/prefix/rhino/lib/xbean.jar
* EvoSuite 0.1-SNAPSHOT
* Unknown class: org.asynchttpclient.Realm
I am told the class is non-existent.
Ideas?
As far as Google revealed EvoSuit needs the compiled class.
My guess is that you eighter didn't compile the class or it landed in a different directory.

Why am I getting a NoClassDefFoundError in java?

I managed to successfully compile my code, but I'm not able to execute it. How do I fix this?
scannerTesting is my package and ScannerTesting.java is my main file.
D:\Java>javac Testing\src\scannerTesting\ScannerTesting.java
D:\Java>java Testing\src\scannerTesting\ScannerTesting
Exception in thread "main" java.lang.NoClassDefFoundError: Testing\src\scannerTesting\ScannerTesting <wrong name: scannerTesting/ScannerTesting>
.
.
.
java -cp ./Testing/src scannerTesting.ScannerTesting
When you run java, it looks for matching classes within its classpath. So what these arguments are doing is add your source folder to the classpath using -cp, and specify that the class that should be run is scannerTesting.ScannerTesting.
For more information, check out java cli tool documentation at Oracle
scannerTesting is your package name,right?
If so, I suggest you run command "java" under the workspace D:\Java\Testing\src
java scannerTesting.ScannerTest

getting error when I compile the Java code using package in commandline?

I have this directory structure:
project1/src/edu/course/firstweek/javacourse/Program1.java
Another file in one package above:
project1/src/edu/course/firstweek/program2.java
In the header of program2.java, I have
package edu.course.firstweek;
import edu.course.firstweek.javacourse.Program1;
Now to when I run the following in commandline:
Javac src/edu/course/firstweek/program2.java, I get this error:
src/edu/course/firstweek/program2.java:14:error cannot find symbol
System.out.println(program1.print("hello world"));
symbol: variable Program1
location: class program2
2 errors
I can see that the compiler is not able to find the program1,but I have the correct import package statement in program2. I need help here and after compiling, is there something that needs to be taken into account for running the program.
Thanks
Try going into one directory inside, i.e. cd src
and then compile Javac edu/course/firstweek/program2.java
for running, do java edu.course.firstweek.program2

Categories