I built a java program that is based on the Youtube Data API command line Examples. The program works fine and I now tried to convert the java class into a JAR file in order for me not having to start eclipse each time I want to use the program. To build the jar file I used the Eclipse export function "File->Export->Java->runnable JAR file".
I also chose to extract all required Libraries into the generated JAR.
All seems to work fine up to the point where I execute the program, which even creates the output file I wanted it to create but the JAR file doesn't seem to be able to retrieve data from the Youtube Data API, which means the created file is empty.
Is there anyone who can help me or at least is experiencing silimar issues?
Below I attached two sample Outputs:
This is what I get when executing the code within eclipse which gives me the correct answer
Channel; Subscribercount
Channelname; 12345
This is what I get when executing the JAR file
Channel; Subscribercount
Channelname; null
It seems that the JAR fails to connect to the API
Here I have a console log:
None of these errors occur when executing within eclipse
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at com.google.api.services.samples.youtube.cmdline.Auth.authorize(Auth.java:51)
at com.google.api.services.samples.youtube.cmdline.data.getChannelsVideos.retrieveChannelInfo(getChannelsVideos.java:220)
at com.google.api.services.samples.youtube.cmdline.data.getChannelsVideos.main(getChannelsVideos.java:49)
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at com.google.api.services.samples.youtube.cmdline.Auth.authorize(Auth.java:51)
at com.google.api.services.samples.youtube.cmdline.data.getChannelsVideos.getChannelsVideo(getChannelsVideos.java:92)
at com.google.api.services.samples.youtube.cmdline.data.getChannelsVideos.main(getChannelsVideos.java:50)
Solved it:I copied the client_secrets.json and the youtube. properties into the same folder as the JAR. Obviously it wasn't possible to import these files from within the JAR structure
Related
I'm currently using gradle and the processing library to make some simple 2D graphics for a java project.
I want to be able to distribute the project when I'm done, and I have been trying to use "gradle distZip" to do this. This creates a zip file, which when unzipped contains a .bat file. However, when I run this script, nothing happens.
I have also tried making a .jar file and using "java -jar FILENAME.jar" however, this results in the error
Error: Could not find or load main class App
Is there something I need to add to my build.gradle file to be able to run a file that uses processing or is there some other way I can bundle my project? Any help is greatly appreciated!
I figured out what I was doing wrong. When I extracted the zip file, I needed to move it to a separate location, extracting it in the same directory doesn't work. Once I moved it to my desktop, everything worked fine.
I want to run a fat client delivered as a Java web start application without Java web start. I launched it via javaws and managed to get all the jar files mentioned in the JNLP file from the cache after they were downloaded.
I tried running the jar file that contains the main class according to the JNLP file, but I get the 'Could not find or load main class' error. Were I just trying to run a class I'd set the classpath accordingly, but since I'm running a jar file with java -jar, as far as I know the classpath settings will be ignored anyway. Now I'm not sure what to do, does anybody know how to tackle this?
I'll answer this myself now, turns out it is stupidly simple: Get all the jar files, unzip them to get the content, merge all the content (best done with rsync), create a new MANIFEST.MF file that contains the main class to be loaded and the merged hashes for all existing files from all MANIFEST.MF files, zip again to create a jar. That's it.
I'm using a java bootstrapping command to update a web application according to an xml file I've configured. The xml file has been checked and it's formatted correctly and referenced correctly in the script.
The problem: I keep getting an error that the system could not find or load the main class.
What I would like to do is to view the contents of the jar file. I know that to do this, I should run:
jar tf jarfilenameandpath
What I don't know is WHERE I should run the command. I tried it from a windows command prompt and received the following error:
'jar' is not recognized as an internal or external command, operable file, or batch file.
You don't have to run that command to see whats there in .jar better
way to do it is download the Java Decompiler
See all the classes and try to find the conflict. If everythings looks fine. The only way you can solve this problem is by debugging it.
Did you set Java PATH variable on your Windows machine?
For more details on de-compilers, visit this page on stackoverflow
I have installed the Vaadin plugin for Eclipse.
I created a test sample project, now I get the following error:
'E:/Programming/Java/Eclipse/configuration/com.vaadin.integration.eclipse/download/gwt-dev/2.3.0/gwt-dev.jar' in project 'test' cannot be read or is not a valid ZIP file
I even went to the above path and copied the file 'gwt-dev.jar' from there into the libraries folder for this web app, however now I am getting this error:
Archive for required library: 'WebContent/WEB-INF/lib/gwt-dev.jar' in project 'test' cannot be read or is not a valid ZIP file
How do I resolve this error? FYI, I am following the instructions given in the book "Learning Vaadin" by Nicolas Frankel to create a test project.
The error seems to suggest that either you don't have the rights to read the file (which I doubt, since you were able to copy it), or the file is damaged. Check that the md5-signature matches with the one given here. If it doesn't match, the file has been corrupted, and you need to download it again.
http://www.jarvana.com/jarvana/browse/com/google/gwt/gwt-dev/2.3.0/
I use sqlite in my java application. When I run it from Netbeans, it works well. The sqlite db file is located in the root project directory (same level as build.xml).
This is the code to access the database file:
DriverManager.getConnection("jdbc:sqlite:database.db");
However, when I build the project, and run the jar file outside netbeans, I always get this error: no such table: table_name
My question: where is the correct location to put the "sqlite db" file? Is it possible to package it inside the JAR file?
I have tried to package my application into a single JAR file (similar to Eclipse's FatJar), but I still get that error. In this case I modify the build.xml as explained in this blog:
Netbeans single JAR
I also tried to create a database folder in the src directory and then put the db file inside the folder (src/database/database.db) and access it using
DriverManager.getConnection("jdbc:sqlite:src/database/database.db");
I can run it inside netbeans. But when I run it outside, I got this error:
path to 'src/database/database.db':C:\Windows\system32\src' does not exist
I know there are similar questions to this in stackoverflow, but most of them don't have a concrete solution. Let me know if someone has found a better one.
Thanks a lot.
Problem solved!
I made a mistake in the way I execute the JAR file. Previously I run the JAR file by right click on it and open it with Java SE binary. I need to do this because in my PC the default program to open JAR file was set to another software.
It turned out that I have to set the default program to Java SE Binary and the double click the JAR file in order to run my application. Using this way I can run and access the sqlite db file without a problem.
I hope this can help others who may get the same problem as I had.
probably you need to point your app to include your app base directory in the classpath.
the command to run your app should be something like:
java -cp . YourAppMainClass
the "-cp . " is the command option that tells java to include current directory in the classpath.