Including javax.usb.properties in a Netbeans run - classpath

I'm trying to run a simple example based on http://usb4java.org/ from a Netbeans 8.1 project Windows 7/64b.
I've created and placed the required javax.usb.properties under the project root directory.
According to the documentation, it must be in the root of the class path.
(cf. http://usb4java.org/quickstart/javax-usb.html)
I made some tries with setting the run configuration by inserting in the VM options (using indifferently -cp or -classpath):
-classpath "." or
-classpath "D:/WORKSPACES/NETBEANS/USBPrototypeControler".
Unfortunately, no configuration is running as expected. I've got every time the exceptions that says the javax.usb.properties is not found.
How could I do with Netbeans?

In Netbeans you need to put the javax.usb.properties file to the src subfolder in you project directory.

Related

How to make an executable jar in net beans (JDK 7)?

I have a project which i need to be made as an executable jar file. I used clean and build option in project, right-click menu and it built normally. The problem is, I cant run the executable jar file in project's dist folder (giving an error saying it could not find the main class, but believe me, I have given the main class correctly). I tried this using an example project (Just a Jframe) and gave me the same error. It can be solved by lowering the JDK version into JDK 6 (current version is JDK 7)but for that i have to do major changes in my actual project (such as replacing all switches into for loops and replacing all multi catches in to single catches...etc). is there any way to make executable jar without changing JDK version?
My netbeans version is 8.0.2
Assuming you have a "private static void main" in you main class.
If you open (not run) the Jar file in the dist folder.
Open the MANIFEST.MF file in /META-INF folder.
Do you see something like Main-Class: com.satra.satra_finacials.view.main.MainFrame ?
If not you can define your main class in Menu File -> Project Properties (Satra_Financials) -> Category Run -> Main Class TextField

Program runs in eclipse, but not in .jar form

I ran it in cmd and it said no main manifest attribute in, JGame2.jar
how do i show it where the main is?? it works fine in eclipse.
For
java -jar x.jar
to work, the jar file must contain a META-INF/MANIFEST.MF file, and this file must contain an entry for the main class. You can add a manifest in Eclipse. Note that any dependencies must also be accounted for, either by:
a class path in the manifest
-cp on the command line
use of some tool to combine to one jar
Eclipse is just an IDE, you might consider learning to use an actual build tool such as Maven or Gradle or Ant to allow you to repeatably build usable results.

Why does eclipse create a class file in bin directory as soon as I create a java file in it?

As soon as I create a java file in eclipse it creates the corresponding class file in the bin directory which I assume is because eclipse compiles any java file as soon as it is created?Am I right?And later does it compile any java project again when I run it?
If you have Project > Build Automatically checked then Eclipse compiles your Java code as you go.
The code is not compiled again when you Run the program.
You are right for the first part (eg: a *.class in the bin directory).
Eclipse does incremental compilation (eg: almost like compile as you type).
For the second part, I don't understand your question.
It will happen in case Build Automatically option is checked (Menu-->Project-->Build Automatically). If you uncheck that option .class file will not be created when you save java file.

How to debug Solr test cases in Eclipse?

When I try to run a Solr test case from Eclipse (Right-Click > Run As > JUnit Test), I get the following printed to the Eclipse console:
Feb 27, 2012 5:21:06 PM org.apache.solr.SolrTestCaseJ4 deleteCore
INFO: ###deleteCore
The whole process runs and exits very quickly without running the actual test case.
I have tried to set my working directory according to the instructions at http://wiki.apache.org/solr/TestingSolr to no avail. Those instructions refer to a directory that doesn't actually exist any more (src/test/test-files), so I tried setting it to solr/core/src/test-files without any luck. I'm using the latest SOLR trunk (as of Feb 27,2012)
What am I missing?
From your own answer looks like you're adding to the classpath a jar which contains the code which should already be in your workspace, thus in your classpath.
The Solr build file has a really handy eclipse target which generates the eclipse project, so you can import it in one click. Just run ant eclipse from the root directory and you shouldn't have problems with classpath.
I hadn't noticed it before, but the test case was throwing an exception saying
A SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene40' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath.The current classpath supports the following names: []
I solved the problem by adding lucene/build/core/lucene-core-4.0-SNAPSHOT.jar to the classpath in the test case's Run Configuration. It feels like I shouldn't have to do this, but I don't have time to investigate further.
If anyone else can tell me how to remove this dependency, I'll attribute the answer to you.
I also had to set the working directory in my Run Configuration to solr/core/src/test-files

java.lang.ClassNotFoundException: org.postgresql.Driver

Whenever I build my project as jar(via NetBeans) it seems that it does not include the postgresql driver library. I remember doing it before without any problems on previous versions of NetBeans and Drivers. I cmd run something like:
C:\Users\Username>java -jar "C:\Users\Username\Documents\NetBeansProjects\OrdersImport\dist\OrdersImport.jar" C:\orders\sometextfile.txt
Should there be something extra to include in this line to add postgresql-9.0-801.jdbc4.jar? I did include library to lib inside of the project and it does work without any troubles if I run it from NetBeans directly. I've looked at my previous project where it did work, seems to be everything same, pathetic I just can't remember, help please.
There should be an entry in your MANIFEST.MF file that references the Postgres driver. And the driver needs to copied so that it's reachable from the real jar files location.
So your MANIFEST.MF needs to include something like this:
Class-Path: lib/postgresql-9.0-801.jdbc4.jar
If the JDBC driver is part of your NetBeans project, NetBeans should have copied it to dist/lib.
If you don't want to change the manifest file (or cannot), you need to manually reference all needed libraries on the command line. But then you cannot use the -jar option any longer:
java -cp postgresql-9.0-801.jdbc4.jar;OrdersImport.jar com.mypackage.MyMain C:\orders\sometextfile.txt
Remember that you have to specify the main class when using -cp or -classpath
You would have to add the postgre jar to your classpath:
C:\Users\Username>java -classpath "location of postgresql-9.0-801.jdbc4.jar" -jar "C:\Users\Username\Documents\NetBeansProjects\OrdersImpo rt\dist\OrdersImport.jar" C:\orders\sometextfile.txt