Strange problem, my package was:
com.myname.myappname
after change is:
com.myname.myappname.abc
and now I cant back to previous name because when I'm going to rename I can change only end of package "abc" and it is not possible to leave this empty field.
so how to set my package to first edition ?
you can do it manually by moving all the files in abc package to parent package & then changing package path in all the files, time consuming but it will work.
Related
Due to some restrictions at my place of employment and lots of red tape, I am currently trying to access a JAR I've uploaded as a Java Resource in Oracle in order to call methods in my own Java source that runs out of the DB JVM.
I've uploaded the JAR and I can see the resource, the DB object is named "Trireme". My Java source is attempting to import this resource traditionally
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Test" AS
// select * from user_errors;
package x.x.x.node;
import io.apigee.trireme.core.NodeEnvironment;
import io.apigee.trireme.core.NodeScript;
...
NodeEnvironment env = new NodeEnvironment();
NodeScript script = env.createScript("my-test-script.js",
new File("my-test-script.js"), null);
....
But it is unable to do so. Is this even possible? Is there a different way to use the classes within the resource, and if so, how is it done? I'm unable to find a good example
EDIT:
To add to this, I've added noticed that if I comment out the code in the class and I do import io.apigee.trireme.core.* and I comment out the lines in the code, it does not fail. Not referencing a specific class lets it compile, but either way, I still get the missing symbol once new NodeEnvironment is called, or NodeEnvironment is mentioned in the import instead of *
I have one Folder by the name of "java" which has two folders "Search","Demo".
in "Search" folder I have so many class including "BinarySearch.java" and in "Demo" folder I have class "Demo.java" I want to import "BinarySearch.java" class in the "Demo.java" class.
So I tried this:
First in "BinarySearch.java" I put this line of code package Search;
in "Demo.java" I put this line of code import Search.BinarySearch.java
But this solution only works only when I move the "Demo.java" file in "java" folder. but I need to import "BinarySearch.java" without moving my file into "java" folder.
See the error If don't move the file into "java" folder
So I need to move back one folder while importing.
Use this:
In Demo/Demo.java
package Demo;
import Search.BinarySearch;
public class Demo {
.
.
.
}
In Search/BinarySearch.java
package Search;
public class BinarySearch {
.
.
.
}
It is always a good practice to use lower case for your package names. Example: demo or search.
The first line of Demo/Demo.java must be "package Demo".
The same as the first line of Search/BinarySearch.java is "package Search".
I have the following file structure in my eclipse workspace
core
src
com.mygame.game (package)
Ability.java
Game.java
...
Allies-Green.java
Ability.java and Game.java were created using the 'right-click on package->New->Class' method. Allies-Green.java, however, was created using the 'right-click on package->New->File' method. Each time I load my workspace, all code that references Allies-Green.java is marked as an error. If I open Allies-Green.java though, and edit one character and resave it, the problem goes away. Does anyone know what could be causing this issue? Here is Allies-Green.java relevant code for reference:
package com.mygame.game;
import java.util.ArrayList;
import ...
//only class in file
class AllyGreen extends Ally {
...
}
Please explain me, why when i run this code, all is fine and i get parent directory of my classes:
URL dirUrl = PathsService.class.getResource("..");
and when I run this code:
URL dirUrl = PathsService.class.getResource("../..");
I get null in dirUrl.
I try like this:
URL dirUrl = PathsService.class.getResource("..//.."); all the same I have a null in dirUrl.
How can I get parent/parent/parent ... directory in Java?
NOTICE:
As others have already stated, basing any functionality on the retrieval of some parent directory is a very bad design idea (and one that is almost certain to fail too).
If you share more details about what you are trying to achieve (the big picture), someone could probably propose a better solution.
That said, you could try the following code:
import java.nio.file.*;
...
Path path = Paths.get(PathsService.class.getResource(".").toURI());
System.out.println(path.getParent()); // <-- Parent directory
System.out.println(path.getParent().getParent()); // <-- Parent of parent directory
Also note, that the above technic may work on your development environment, but may (and probably will) produce unexpected results when your application is "properly" deployed.
The result you are getting is perfectly right.
I think you have misunderstood the use of class.getResource.
Lets say you have package com.test and MyClass inside this package.
This MyClass.class.getResource(".") will give you the location of the file you are executing from. Means location of MyClass.
This MyClass.class.getResource("..") will go 1 level up in your package structure. So, this will return the location of directory test.
This MyClass.class.getResource("../..") will go further 1 level up. So, this will return the location of directory com.
Now, this MyClass.class.getResource("../../..") will attempt to go further 1 level up but since there is no package directory exists, this will return null.
So, class.getResource will not go out of the defined package structure and start accessing your computer directory. This is how this does not work. This only searches within your current class package structure.
I'm having problems when trying to compile the following code:
I first tried compiling with this code:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
it works as it should. Now, if I try to replace the class name for any other name, it won't work anymore, as it seems to always look after HelloWorldApp. I made sure the file is being saved and so, I even reopened Eclipse. Still the same error. Maybe this is a common problem, with a small work-around?
Thanks
edit: I see what you guys mean, but why does it work when I have the file name as "Main.java" and a class name of "HelloWorldApp" ?
You need to rename your .java file to match the class name.
Eclipse will rename your .java file to match your class name automatically if you use its refactoring support. Right click on the class name, hover over Refactor, and select the Rename option. Now when you rename your class, Eclipse will automatically rename your .java file to match.
This is how Java works. Class must have the same name as the file. So the filename for the class MyApp, must be MyApp.java
Rename main as HelloWorldApp so that your app becomes HelloWorldApp.java.
When changing the name of your class use the REFACTOR option - If you try to edit the name manually yourself the Eclipse Project loses track of your objects.