How do I compile a Jar w/ a external lib - jar

Well I'm new to to stackoverflow so I'm sorry if I misinterpreted some of this Q&A rules feel free to point out any mistake, and for my English, since I'm not an English native speaker.
Now, although I program for several years, I've been forced to use an old version of JDeveloper on this project I'm in, and I've had some beginner issues, because I'm used to let the IDE do all the hard work.
My objective is, to compile my project to a jar and execute it in the server.
So far, I got my app to run and work on my IDE which is JDev 9.0.3.2 (OLD) and Java version is 1.3.1_01, but when I try to compile to a jar file for some reason the lib doesn't come along.
My code (partially ofc):
Connection con = null;
public Depositos() throws Exception {
System.out.println("Beginning ORACLE DB connection");
try {
String connstr="jdbc:oracle:thin:"+"#<hostname>"+":"+"<port>"+":"+"<SID>";
System.out.println("connstr ok");
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Class.forName ok");
con = DriverManager.getConnection (connstr, "cic", "managercic");
System.out.println("Connection successful");
} catch (ClassNotFoundException e) {
throw new Exception("DB connection error "+e.getMessage());
}
}
And I suspect the problem is over here, more precisely in here:
"Class.forName("oracle.jdbc.driver.OracleDriver"); "
My procedure is:
On the Depositos.java folder
I run this:
javac -verbose Depositos.java -classpath C:\oracle\ora92\jdbc\lib\classes12.jar
the output says it's all OK.
jar cfmv0 Depositos.jar MANIFEST.MF Depositos.class C:\oracle\ora92\jdbc\lib\classes12.jar
my MANIFEST.MF contains:
Manifest-Version: 1.0
Created-By: Oracle JDeveloper 10.1.3.4.0
Main-Class: Depositos.Depositos
When I run the code from the src folder with:
java oic.OIC
my output is:
Beginning ORACLE DB connection
connstr ok
Exception in thread "main" java.lang.Exception: DB connection error oracle.jdbc.driver.OracleDriver
at Depositos.Depositos.<init>(Depositos.java:47)
at Depositos.Depositos.main(Depositos.java:98)
Which leads me to the conclusion that the error is in the line I stated above.
And I don't understand what I did wrong, I've read so many post from other forums, I don't know what's the right move anymore.
I tried several combinations of compiling commands.
Thank you for your help.

You can add the oracle jar to your jar, and put a 'Class-path' attribute in the manifest.
Manifest-Version: 1.0
Created-By: Oracle JDeveloper 10.1.3.4.0
Main-Class: Depositos.Depositos
Class-path: <path to jar inside your jar>
From memory though, if your jar is signed, you need to sign the jars within it also.

Related

Resetting Arduino via code

I have looked at a dozen different ways to reset my arduino, from connecting pins to the reset pin and jury rigging weird bits of code.
None of them work.
The one bit of code that everybody seems to be using is
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
To which my arduino responds with
C:\Users\Leonardo\AppData\Local\Temp\ccGUYdTQ.s:2259: Error: bad
instruction `jmp 0'
And it then fails uploading the code. I don't know what to do. My full code can be found here http://pastebin.com/CA2Ms2hB but it's huge and I'm not sure if it will be of help.
If anyone could help me understand why software_Reset(); I would really appreciate it, I'm at the end of my rope here.
(also if you have other methods to reset arduino I'll gladly try them)
On ARM based microcontrollers you can call NVIC_SystemReset().
All ARM based microcontrollers are required to implement that.
This is useful because resetFunc() at address 0 may not work on newer ARM based microcontrollers.
I think you are trying to write assembly code in your arduino code editor.
Let me tell you one thing. Arduino code editor does not support assembly language code by default. You can write assembly language code in arduino code editor by going through the process mentioned below:
Caution: We will be modifying the arduino source code to do that.
Get the source code for Arduino IDE: https://github.com/arduino/arduino
Extract the downloaded zip file, you will get a folder named Arduino-master
Open the Sketch.java file in a text editor of your choice. The location of sketch.java is : Arduino-master/app/src/processing/app/Sketch.java
Insert the .s capability:
a. Search for: sc.isExtension("c");
you will see something like this:
//3. then loop over the code[] and save each .java file
for (SketchCode sc : code){
if(sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")){
//no pre-processing services necessary for java files
b. Add sc.isExtension("s") at the end of the if condition. Now your code should look like below:
//3. then loop over the code[] and save each .java file
for (SketchCode sc : code){
if(sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h") || sc.isExtension("s")){
//no pre-processing services necessary for java files
Search for: String[] getExtensions()
You will see some code like this:
/**
* Returns a String[] array of proper extensions.
*/
public String[] getExtensions() {
return new String[] { "ino", "pde", "c", "cpp", "h" };
}
Insert "s" in the returned Array. So, now your code should look like this:
/**
* Returns a String[] array of proper extensions.
*/
public String[] getExtensions() {
return new String[] { "ino", "pde", "c", "cpp", "h", "s" };
}
Save Sketch.java
Open Compiler.java in text editor of your choice. The location of Compiler.java is: Arduino-master/app/src/processing/app/debug/Compiler.java
Search for: compileFiles(
In the command findFilesInFolder(), replace the capital S with a lowercase s.
Repeat step 8 : 3 times more... (4 tiems in total)
Save the Compiler.java file
Download the latest version of java SE 8u111 from http://www.oracle.com
Download and install any java command line tool. But I would recommend Apache ANT.
If you are a windows user:
You can download it here: http://ant.apache.org/
More help on download and install on windows: https://www.mkyong.com/ant/how-to-install-apache-ant-on-windows/
If you are a Mac user:
You need to install it using Homwbrew:
To install Homebrew:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
And then to install Apache ANT:
brew install ant
In Command line go to the directory for Arduino-master/build
Build the Arduino IDE using : ant build, which should end with Build Successful message.
Package the Arduino IDE using: ant dist
It will ask you to enter a version number and give a suggestion e.g.[0105]. Just enter the suggested number with dots and asm. For example: If suggestion is [0105] then enter: 1.0.5.asm
This command may take 6 - 10 minutes to finish. (depending on the speed of your computer)
Then you must get Build Successful!!!
The Arduino IDE that supports assembly language programming can be found in the newly created .zip file
Unzip the file and install the Arduino IDE application.
Now, you should be able to write assembly programs without getting errors in the Arduino IDE.
If you have any problems, Please feel free to ask.

Apache spark-shell error import jars

I have a local spark 1.5.2 (hadoop 2.4) installation on Windows as explained here.
I'm trying to import a jar file that I created in Java using maven (the jar is jmatrw that I uploaded on here on github). Note the jar does not include a spark program and it has no dependencies to spark. I tried the following steps, but no one seems to work in my installation:
I copied the library in "E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar"
Edit spark-env.sh and add SPARK_CLASSPATH="E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar"
In a command window I run > spark-shell --jars "E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar", but it says "Warning: skip remote jar"
In the spark shell I tried to do scala> sc.addJar("E:/installprogram/spark-1.5.2-bin-hadoop2.4/lib/jmatrw-v0.1-beta.jar"), it says "INFO: added jar ... with timestamp"
When I type scala> import it.prz.jmatrw.JMATData, spark-shell replies with error: not found: value it.
I spent lot of time searching on Stackoverflow and on Google, indeed a similar Stakoverflow question is here, but I'm still not able to import my custom jar.
Thanks
There are two settings in 1.5.2 to reference an external jar. You can add it for the driver or for the executor(s).
I'm doing this by adding settings to the spark-defaults.conf, but you can set these at spark-shell or in SparkConf.
spark.driver.extraClassPath /path/to/jar/*
spark.executor.extraClassPath /path/to/jar/*
I don't see anything really wrong with the way you are doing it, but you could try the conf approach above, or setting these using SparkConf
val conf = new SparkConf()
conf.set("spark.driver.extraClassPath", "/path/to/jar/*")
val sc = new SparkContext(conf)
In general, I haven't enjoyed working with Spark on Windows. Try to get onto Unix/Linux.

MonoDevelop Error - System.DllNotFoundException: libclntsh.so

I have created a C# console project using Visual Studio 2008 and OracleClient (OCI) libraries to connect to a Oracle 11g database. This code works in Windows. I copied the whole project into Linux and Open the solution using MonoDevelop 4.2.3. But while running the project, the Database Open call throws an exception
string connectionString = "Data Source=Test; User ID=UID; Password=PWD"
OracleConnection conn = new OracleConnection()
conn.ConnectionString = connectionString;
conn.Open();
Exception:
System.DllNotFoundException: libclntsh.so at (wrapper
managed-to-native)
System.Data.OracleClient.Oci.OciCalls/OciNativeCalls:OCIEnvCreate
The libclntsh.so file is under the location /home/dbuser/instantclient_12_1
I have set the environment variable by adding the below in the /home/dbuser/.bashrc file and rebooted the system.
export
LD_LIBRARY_PATH=/home/dbuser/instantclient_12_1:$LD_LIBRARY_PATH
But still I am getting the same error. I couldn't find any option to include the Libraries in the MonoDevelop.
Thanks
Looks like LD_LIBRARY_PATH environment variable is not set up correctly or does not get applied.
Try creating additional linker configuration file instead with the following command:
echo /home/dbuser/instantclient_12_1 > /etc/ld.so.conf.d/instantclient.conf
Then as root update linker cache with command:
ldconfig
Restart MonoDevelop and try again.
I have resolved the issue by doing the following
echo $ORACLE_HOME/lib > /etc/ld.so.conf.d/dbconf.conf
set the$ORACLE_HOME, $ORACLE_INCLUDE_PATH and $ORACLE_LIB_PATH to
/etc/profile.d
Because of some reason MonoDevelop IDE is not picking the library libclntsh.so if I use the OCI client libraries

javacc testing Simple1.jj

If you see my other question, you will now better my goals. Take a look at: https://stackoverflow.com/questions/19510039/from-regex-to-parser-generators .
As I'm trying to be a good boy, I'm reading the README (see https://java.net/projects/javacc/sources/svn/show/tags/release_60/examples/SimpleExamples?rev=555 ).
Run javacc on the grammar input file to generate a bunch of Java files that implement the parser and lexical analyzer (or token
manager):
javacc Simple1.jj
Now compile the resulting Java programs:
javac *.java
The parser is now ready to use. To run the parser, type:
java Simple1
My try:
D:\tests\javacc\simple1>javacc ..\Simple1.jj
Java Compiler Compiler Version 6.0_beta (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file ..\Simple1.jj . . .
File "TokenMgrError.java" does not exist. Will create one.
File "ParseException.java" does not exist. Will create one.
File "Token.java" does not exist. Will create one.
File "SimpleCharStream.java" does not exist. Will create one.
Parser generated successfully.
D:\tests\javacc\simple1>javac *.java
SimpleCharStream.java:474: error: non-static variable this cannot be referenced from a static context
static void setTrackLineColumn(boolean trackLineColumn) { this.trackLineColumn = trackLineColumn; }
^
1 error
My java version:
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode, sharing)
I'm sure that "these" guys known what they are doing, I'm sure I did something wrong, but what? Getting a simple error like that in the first test with javacc?
How can I fix that and continue my lecture?
I suggest using version 5.0 for now. There are a lot of changes in version 6 and these came along with some bugs. There should be an update to version 6 soon. https://java.net/projects/javacc/downloads
Will you put the code to look it or your complete call. I think, that it´s a code error or that you call a bad .java archive. For example:
I have: Mytokens.jj and javaCode.java ok? Good, you need said:
javacc Mytokens.jj
javac javaCode.java
java javaCode <test1.txt>
I give you my *.bat for the test. You create a new txt and write it:
CALL javacc nameJJ.jj
#pause
CALL javac NameJava.java
#pause
java NameJava <prueba1> salida.txt
type salida.txt
#pause
This do the test for you when you do a double-click on it if you have a copy in your javacc/bin and your practice directories.

Documentum NPE when running as jar

I'm writing a simple application to create a Documentum folder structure from a directory structure on disk. When I run the application through SpringSource Tool Suite, it works fine. When I package it as a jar, with all dependencies, and run it, I receive the following error:
java.lang.NullPointerException
at com.documentum.fc.common.impl.preferences.PreferencesManager.locateMainPersistentStore(PreferencesManager.java:372)
at com.documentum.fc.common.impl.preferences.PreferencesManager.readPersistentProperties(PreferencesManager.java:333)
at com.documentum.fc.common.impl.preferences.PreferencesManager.<init>(PreferencesManager.java:41)
at com.documentum.fc.common.DfPreferences.initialize(DfPreferences.java:64)
at com.documentum.fc.common.DfPreferences.getInstance(DfPreferences.java:43)
at com.documentum.fc.client.DfSimpleDbor.getDefaultDbor(DfSimpleDbor.java:78)
at com.documentum.fc.client.DfSimpleDbor.<init>(DfSimpleDbor.java:66)
at com.documentum.fc.client.DfClient$ClientImpl.<init>(DfClient.java:344)
at com.documentum.fc.client.DfClient.<clinit>(DfClient.java:754)
Here is the line in my code where this error occurs:
IDfClient client = DfClient.getLocalClient();
The jar includes the dfc.properties file, which I specify on the command line using
-Ddfc.properties.file=dfc.properties.dev
For the record, the full command line looks like this (slightly anonymized):
java -Ddfc.properties.file=dfc.properties.dev -jar MyTest-jar-with-dependencies.jar baseDirectory baseDocumentumFolder
Thanks much for your time!

Resources