X3D files won't load with a URL - java

I'm making a Xj3D Test class in Java and it's meant to display X3D and X3DV files. It does work with some test files. But when it comes to the X3D files that I've been given, they don't get displayed and I get an error saying:
Exception in thread "main" org.web3d.x3d.sai.InvalidURLException: Unable to load any URLS
at org.web3d.vrml.scripting.external.sai.SAIBrowser.createX3DFromURL(SAIBrowser.java:846)
at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:50)
at xj3dtest.Xj3DTest.main(Xj3DTest.java:56)
I've done some research and I've seen that I might need to use the createX3DFromStream method instead of the createX3DFromURL method that I currently have in my Java code. I realise that it's the URL within the X3D and X3DV files that's causeing the problem and I need to get rid of the error as it's prohibiting me from continuing the project. The line in my Java code that's causing the problem is: X3DScene scene = browser.createX3DFromURL(new String[] {"hafodty_cirlce_1.x3dv"});. I have the X3DV file hafodty_circle.x3dv saved within my NetbeansProject folder for the project.
EDIT
The way that I got the Browser element was by the following line.
Browser browser = x3dComponent.getBrowser();

Related

JavaFX + SpringBoot, cant load css

i need a help understanding what is happening in my project, anyways i have javafx with springboot:
i have folder structure like this :
So i want to access from my java/controller folder, and i need my css file that is under resources folder, in css folder.
I tried every possible way, to load my css and nothing seems to work except :
Directly loading css through fxml (which i wish to evade)
using this code also works, but only in IDE, if i create JAR it does not work anymore :
File f = new File("src/main/resources/css/main.css");
paneRoot.getStylesheets().add("file:///" + f.getAbsolutePath().replace("\\", "/"));
When i do check of f.exists() i get true, so path is ok, but when i use this :
paneRoot.getStylesheets().add(getClass().getResource("src/main/resources/css/main.css").toExternalForm());
or
paneRoot.getStylesheets().add("src/main/resources/css/main.css");
it does not work,in first code line, where i use .toExternalForm(), program crashes reporting nullPointer.
Now i honestly do not know what is issues here, i tried with 2 different IDE-s, i tried clearing cashe, rebulding and cleaning application, but every time same issue.
If i need to provide further code, i will i just need to understand this.

java.nio.file.InvalidPathException with getPath

I am using this code
String path = getClass().getResource("Template.xls").getPath();
When I run it on my machine (windows), everything is good. I even did system.out.println on the get resource part and on the get path part and the results were:
file:/C:/Eclipse/Netbeans/SoftwareCom/build/classes/assets/Template.xls
/C:/Eclipse/Netbeans/SoftwareCom/build/classes/assets/Template.xls
However I am getting the following error reports from some users
java.nio.file.InvalidPathException: Illegal char <:> at index 4:
file:\C:\Software%20Com\SoftwareCom.exe!\assets\Template.xls
Iam not sure whats happening or why would it work for some and not others
Any pointers?
To answer this question properly, it would be helpful to know what you want to do with the path information. To read the file, you don't need the path.
You could just call
getClass().getResourceAsStream("Template.xls")
If you really want to know the path, you should call
URL url = getClass().getResource("Template.xls");
Path dest = Paths.get(url.toURI());
This might cause problems as you seem to pack your java files in a windows executable. See Error in URL.getFile()
Edit for your comment:
As I wrote above, you don't need the path of the source to copy. You can use
getClass().getResourceAsStream("Template.xls")
to get the content of the file and write the content to whereever you want to write it. The reason for failing is that the file in your second example is contained within an executable file:
file:\C:\Software%20Com\SoftwareCom.exe
as can be seen from the path:
file:\C:\Software%20Com\SoftwareCom.exe!\assets\Template.xls
The exclamation mark indicates that the resource is within that file.
It works within Netbeans because there the resource is not packed in a jar, but rather is a separate file on the filesystem.
You should try to run the exe-version on your machine. It will most likely fail as well. If you want more information or help, please provide the complete code.
I faced this same issue and go around it by using the good ol' File API
URL url = MyClass.class.getClassLoader().getResource("myScript.sh");
Path scriptPath = new File(url.getPath()).toPath();
And it worked!

Tibco-java Custom function error

I created one custom java function in TIBCO designer. I loaded class file from my desktop. It was working fine. But, now I did some changes in that function and then created and loaded class file, but this time class file location is different(from clearcase). This cause an error where I used this function earlier and the error is :
"No function in namespace:java://xyz"(xyz is class file name which I not changed).
Please help me to resolve this error without changing previous code.
Please check your package hierarchy in the Java file, if there is no change, looks like your Designer did not pick up the latest .class file from the new location.
1. Retry by completely closing your designer instances in your machine.
2. Reload by browsing the new .class file and save your project.
3. Check by validating this particular process only.
Hope you are out of this issue already.

How can I get Eclipse to find my .txt file in java ON A MAC? [duplicate]

I need to write a program that asks for the file name of a text document of number and then calculates average, median, etc., from this data set. I have written the program so that runs correctly when I input the full path such as "C:\Users\COSC\Documents\inputValues2.txt", however it will not run when I simply input inputValues2.txt. I have been researching the different between the two but am not fully understanding how to fix this. Since it is running correctly, otherwise, I don't believe it is a problem with the code, but I am new to this so I may be wrong.
Your program needs to know the full path in order to find the file. It isn't just searching your computer for the file "inputValues2.txt". It needs to know exactly how to get there. If you wanted to, you could move the file into your project folder, and then you would just be able to write "inputValues2.txt" to access it. I normally create a folder called "res" in my project folder, and then let's say I am trying to create an image:
Image i = new Image("res/img.png");
Your file should be in the class-path. That's in the same directory that your main class is in.
The suggested practice is to place it in a Resources directory inside your class-path, then you can access it via, "Resources/inputValues2.txt".

Java: find the main class of a JAR file on a website

I am writing a program that connects to a web host that has a directory containing a couple JAR files. Then, a GUI shows the JAR name and when you double click on the name, it will open the JAR file.
The problem that I am having is, not all of the JAR files have the main method in the same place, so I need some way of finding the main class.
I have tried doing an approach like this:
File file = new File("website/test.jar");
JarFile jar = new JarFile(file);
String mainClass = jar.getManifest().getMainAttributes().get("Main-Class").toString();
However, I get:
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
On the line where a JarFile object is created. I have thought of two solutions: go through all the class files in the JAR and search for the one that contains the main method, or create a text file in the directory that tells the main file of each JAR.
I would prefer to use the first solution, because it does not actually require me to do extra steps every time I upload another JAR. However, I am concerned that it is kind of a "brute-force" alternative, and it feels inefficient.
Have any of you experienced a similar problems?
Thanks a lot!
See this :
http://docs.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html

Categories

Resources