Creating library jar with other libraries - exception

I am creating jar via eclipse, but not runnable jar, it is just a library. After importing that i'm creating new project and adding this jar file. But when run application it throws exception about not finding libraries which are inside in my jar. But these libraries are included in created jar. Where is my mistake ? How can I do that ?

You cannot, by default, include dependency JAR files inside your JAR file, you need a plugin, as specified in Classpath including JAR within a JAR (suggested by Artur Malinowski). If, however, you wish to create a JAR which simply works with your other dependencies, you can easily do this via Eclipse by right clicking on the project, going into properties, Java Build Path, Libraries and then you can add JARs, etc. by using the buttons along the right side of the menu (as of Kepler).
I hope this helps.
P.S. You'll have to cart round the dependency JAR files wherever you put the main JAR, however, this is the easiest and most straightforward approach to getting it working in the first place, and then refine later, using build plugins.

I found the solution. I write some ant script for creating jar and it was solved my problem.
<target name="dist" depends="build-jar">
<property name="store.jar.name" value="MYJARNAME"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging project into a single JAR at ${store.jar}"/>
<mkdir dir="dist"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<mkdir dir="dist/lib"/>
<copy todir="dist/lib/" overwrite="false" granularity="9223372036854">
<fileset dir="lib/"/>
</copy>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>

Related

Camel Bindy application JBoss EAP 6.1 Deployment issue

I am trying to deploy a camel application which reads CSV file and process it.I am trying to use camel bindy to unmarshal the csv to POJO.
The camel bindy module was not available in jboss EAP i have added it.
Camel Route:
<?xml version="1.0" encoding="ASCII"?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="switchyard://FileService" />
<log message="inside route" />
<doTry>
<split streaming="true">
<tokenize token="/n"></tokenize>
<unmarshal ref="bindyDataformat" >
<bindy classType="com.agcs.bih.prototypes.filetosca.Student" type="Csv"/>
</unmarshal>
<process ref="ProcessCSV"></process>
</split>
<doCatch>
<exception>java.lang.Exception</exception>
<log message="FileToScaRoute - message received: ${exception.message}" />
</doCatch>
</doTry>
</route>
</routes>
Iam getting the below exception during deployment.
Caused by: java.lang.IllegalArgumentException: Data format 'bindy-csv' could not be created. Ensure that the data format is valid and the associated Camel component is present on the classpath
Attaching server.log
Can you please help
It sounds like you are using JBoss FSW possibly? Fuse 6.3 on EAP 6.3 includes camel-bindy and there's an example included there for SwitchYard as well if you can upgrade.
Please see;
http://camel.apache.org/bindy.html
Make sure you have created bindyDataFormat
<dataFormats>
<bindy id="bindyDataformat" type="Csv" classType="org.apache.camel.bindy.model.Order"/>
</dataFormats>
After refering the link https://developer.jboss.org/thread/177124.I have added the manifest entry in maven jar plugin pom xml
<manifestEntries>
<Dependencies>org.apache.camel.bindy export services</Dependencies>
</manifestEntries>
iam able to unmarshal it to pojo using camel bindy now.

How do I include appsettings.json configuration settings in a nuget package?

I am running .net core 1.1, nuget 3.5, and hosting packages on VS team services.
I looked into transformations here: https://learn.microsoft.com/en-us/nuget/create-packages/source-and-config-file-transformations,
But I need a solution for json files, not config files.
I read that you can use an install.ps1 script to include the file, but I also read that install.ps1 is deprecated.
What is the current method for including json configuration files in a nuget package?
Try to use <files> node in the .nuspec file. Example from here:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<!-- ... -->
</metadata>
<files>
<!-- Add a readme -->
<file src="readme.txt" target="" />
<!-- Add files from an arbitrary folder that's not necessarily in the project -->
<file src="..\..\SomeRoot\**\*.*" target="" />
</files>
</package>

Visual Studio Team Services release XML transformation doesn't work

Visual Studio Team Services - Build & Release
In the release definition, under File Transforms & Variable Substitution Options, there are XML transformation, and XML variable substitution.
I checked both checkboxes, but after deployment, nothing in my Web.Dev.config replaces web.config. The transformation doesn't happen at all.
What is the problem?
--------edit: detail---------
build
all the settings here is default.
release
web.dev.config
This transformation works fine if I deploy from visual studio 2015.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=tcp:xxxx.database.windows.net,1433;Database=xxxx;User ID=xxx#xxx;Password=xxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="NicoContext" connectionString="metadata=res://*/Nico.csdl|res://*/Nico.ssdl|res://*/Nico.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:xxxx.database.windows.net,1433;initial catalog=xxxx;User Id=xxxx#xxxx;Password=xxxx;App=EntityFramework"" providerName="System.Data.EntityClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<appSettings>
<add key="Environment" value="Dev" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
<add key="AzureStorageContainerName" value="xxx" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="FacebookLoginAppId" value="xxx" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
<add key="FacebookLoginAppSecret" value="xxx" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
--------edit 2: no longer work ---------
I did as the solution suggested on a new project in another Azure account, but this time it didn't work. For build, I choose template "Asp.net (preview)", for release, I choose template "Azure App Service Deployment".
--------edit 3: Release - Package or folder ---------
You have already deployed/published the web app, so the web.config has already been transformed (For web package deployment, the related values in web.config will be updated during web deploy, the values are in parameters.xml).
So, there isn’t other config files (e..g web.dev.config, web.release.config) in published folder and check XML transformation and XML variable substitution is useless.
Based on the build log, the web app build with release configuration, but there isn’t web.release.config, so there isn’t update for web.config.
You can refer to these steps to achieve your requirement:
Publish/deploy the web app with File System way (e.g. /p:WebPublishMethod=FileSystem /p:publishUrl= $(build.artifactstagingdirectory)\)
Add Copy file step copy others config files (web.dev.config, web.prod.config etc) to the published folder (artifact directory)
Add Publish Build Artifacts
For release, uncheck Publish using Web Deploy option and specify $(System.DefaultWorkingDirectory) to Package or folder.

Hibernate question

I getting an error when running my program. the error is: org.hibernate.HibernateException: JDBC Driver class not found: com.mysql.jdbc.Driver.
The driver is there...I am not sure what it causing this. Any suggestions?
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/registrar</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="com/ths/entity/Course.hbm.xml"/>
<mapping resource="com/ths/entity/Student.hbm.xml"/>
<mapping resource="com/ths/entity/Enrollment.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The driver is there...I am not sure what it causing this.
The driver is not there. The error is simple: the Java VM couldn't find your driver. So, double-check the classpath. If you are deploying a web-application, make sure your driver is in the server's lib, and not in WEB-INF/lib.
You may have that jar in project but class loader is unable to find that as class loader does not check each and every folder of project. If it is a web application then you need to put jar file in WEB-INF/LIB.
If it is a standalone application then you need to add jar file in build path.
you can check class path during run time to see whether folder (where jar exist) is considered in class path or not.
I am not sure what was causing this. I was trying this on my work computer. I tried it at home and it worked fine. Must just be a setting.

Mysql, NHibernate and visual studio 2008 configuration

I am a beginer with visual studio 2008 (C#), mysql and NHibernate.
I have problems with mysql connector as I don't know how to add reference to it.
In my project I have:
/lib/mysql-connector-net-6.1.4-src/
(downloaded from http://dev.mysql.com/downloads/mirror.php?id=387799#mirrors)
Now I right click on my project -> addReference -> browse -> What now?
Should I also edit my hibernate configuration?
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=localhost;database=Pets;Database=pets,User ID=root,Password=;</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property>
<property name="show_sql">false</property>
</session-factory>
</hibernate-configuration>
Thanks
You need to add a reference to the MySQL connector DLL that corresponds to the version of .NET you are targeting.
From the link provided, it seems like you downloaded the source code for the MySQL connector, so you'll either need to build this code and take the desired DLL out of the /bin folder afterwards or download a full installer (which will include the binaries) from the second link here:
http://dev.mysql.com/downloads/connector/net/6.1.html
Once you add this DLL to your project, you'll need to edit that NHibernate configuration to update the "connection.connection_string" property with the connection string for your database.
Hope this helps. There is some more documentation available here:
http://dev.mysql.com/doc/refman/5.1/en/connector-net.html